{
"_id" : ObjectId("5d0b5b7d054a183d24d34a6b"),
"name" : "Ian Fleming",
"age" : 18,
"address" : [
{
"_id" : ObjectId("5d0b5b7d054a183d24d34a6d"),
"city" : "福建"
},
{
"_id" : ObjectId("5d0b5b7d054a183d24d34a6c"),
"city" : "上海"
}
],
"__v" : 0
}
实例:
const Mongodb = require("./mongodb");
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const personSchema = Schema({
_id: Schema.Types.ObjectId,
name: String,
age: Number,
address:[{
city:String
}]
});
const Person = Mongodb.model('persons', personSchema);
const author = {
_id: new mongoose.Types.ObjectId(),
name: 'Ian Fleming',
age: 18,
address:[
{city: "福建"},
{city: "上海"}
]
};
Person.find({"address.city":"福建"}).exec(function (err,data) {
console.log(data[0].address[0].city);//福建
});