I'm still learning Mongodb, Nodejs, and Mongoose, so please excuse my ignorance if this question lacks understanding.
I find it somewhat redundant that each Mongodb collection have to be dissected in Mongoose. Specifically, all the fields of each Mongodb collection and their types need to be stated in Mongoose's schema.
So if I have a collection that contains documents sharing the same fields, such as:
> db.people.find()
{ "_id" : ObjectId("1111"), "name" : "Alice", "age": 30 }
{ "_id" : ObjectId("2222"), "name" : "Bob", "age": 25 }
{ "_id" : ObjectId("3333"), "name" : "Charlie", "age": 40 }
The way that Mongoose+Nodejs connect to this Mongodb
var mongoose = require('mongoose');
var personSchema = new mongoose.Schema({
name : String,
age : Number
});
mongoose.model("Person", personSchema, 'people');
where the last line contains the collection name as the 3rd parameter (explained here).
Is it possible to have Mongoose automatically extract the schema somehow from a Mongodb collection for a collection that contains documents of identical fields (i.e. they would have the same schema)? So that we don't have to define the schema in Mongoose.