这是我的图式
var elementSchema = new Schema({ name: String, storage: { url: String, type: String } });
但是当我:
var newElement = new Element(); newElement.storage = {}; newElement.storage.url = "asd"; newElement.storage.type = "asd"; console.log(newElement.storage);
我得到了[object Object],虽然它应该返回{url:"asd",type:"asd"}
[object Object]
{url:"asd",type:"asd"}
实际上,如果我去查询它,我会得到:
{ storage: "[object Object]", bubble: ObjectId("510880b82e6e350200000002"), _id: ObjectId("5113c0c0786ece0000000001"), __v: 0 }
要使用type嵌入式子文档(如)中命名的字段storage,您必须使用显式定义,否则Mongoose会感到困惑:
type
storage
var elementSchema = new Schema({ name: String, storage: { url: String, type: { type: String } } });