code: def test_train_model():
      """Test the dataset by training a tf.keras model"""
  
      dataset = tfio.experimental.mongodb.MongoDBIODataset(
          uri=URI, database=DATABASE, collection=COLLECTION
      )
      dataset = dataset.map(
          lambda x: tfio.experimental.serialization.decode_json(
              x, specs=SPECS
          )
      )
      dataset = dataset.map(lambda v: (v, v.pop("survived")))
      dataset = dataset.batch(BATCH_SIZE)
  
      assert issubclass(type(dataset), tf.data.Dataset)
  
      feature_columns = []
  
      # Numeric column
      fare_column = feature_column.numeric_column("fare")
      feature_columns.append(fare_column)
  
      # Bucketized column
      age = feature_column.numeric_column("age")
      age_buckets = feature_column.bucketized_column(
          age, boundaries=[10, 30]
      )
      feature_columns.append(age_buckets)
  
      # Categorical column
      gender = feature_column.categorical_column_with_vocabulary_list(
          "gender", ["Male", "Female"]
      )
      gender_indicator = feature_column.indicator_column(gender)
      feature_columns.append(gender_indicator)
  
      # Convert the feature columns into a tf.keras layer
      feature_layer = tf.keras.layers.DenseFeatures(feature_columns)
  
      # Build the model
      model = tf.keras.Sequential(
          [
              feature_layer,
              layers.Dense(128, activation="relu"),
              layers.Dense(128, activation="relu"),
              layers.Dropout(0.1),
              layers.Dense(1),
          ]
      )
  
      # Compile the model
      model.compile(
          optimizer="adam",
          loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
          metrics=["accuracy"],
      )
  
      # train the model
      model.fit(dataset, epochs=5)
  
file_path: io/tests/test_mongodb.py
imports: import socket
  import pytest
  import tensorflow
  from tensorflow import feature_column
  from tensorflow.keras import layers
  import tensorflow_io
label_desc: Use image node_id 4 for calling a global function with example usage: test_train_model() without return types