Mongoose
const { createAgent } = require('@forestadmin/agent');
const { createMongooseDataSource } = require('@forestadmin/datasource-mongoose');
const connection = require('./mongoose-models');
// Create agent and import collections from mongoose.connection
const agent = createAgent(options).addDataSource(
createMongooseDataSource(connection, { flattenMode: 'none' }),
);const mongoose = require('mongoose');
const connectionString = 'mongodb://root:password@localhost:27017';
const connection = mongoose.createConnection(connectionString);
connection.model(
'persons',
new mongoose.Schema({
name: String,
age: Number,
// Nested object
address: { streetName: String, city: String, country: String },
// List of nested objects
bills: [{ title: String, amount: Number, issueDate: Date, payedBy: [String] }],
}),
);
module.exports = connection;Dealing with deeply nested models

Understanding flattenMode
flattenModeDescription
Example
Last updated