내 문서에 클라이언트 ID의 배열이 포함될 것으로 예상되는 clients
이라는 필드가 있습니다.몽구스에 ObjectId의 배열 채우기
{
"first_name":"Nick",
"last_name":"Parsons",
"email":"[email protected]",
"password":"foo",
"clients":[
"50f5e901545cf990c500000f",
"50f5e90b545cf990c5000010"
]
}
내 데이터가 JSON으로 전송되며 직접 Mongo로 보내 문서를 만듭니다. 어떤 이유로 인해 내가 만들 때 clients
이 채워지지 않으므로 수동으로 문자열로 입력해야합니다.
내 스키마는 매우 간단, 다음과 같이 정의 : 올바르게 내 이해에서
var userSchema = new Schema({
first_name: {
type: String,
trim: true
},
last_name: {
type: String,
trim: true
},
email: {
type: String,
trim: true,
lowercase: true,
index: true,
unique: true,
required: true
},
password: String,
clients: [Schema.Types.ObjectId]
});
, 내가 정의한 클라이언트를. 하지만 내가 만들 때 클라이언트 배열을 채울 수 없습니다. 몽고로 전달 된 원시 개체가 좋아 보인다.
{
first_name: 'Zack',
last_name: 'S',
email: '[email protected]',
password: 'test',
clients: [
'50f5e901545cf990c500000f',
'50f5e90b545cf990c5000010'
]
}
올바르게 입력했기 때문에 입력 한 내용에 특별한 것이 있습니까?
귀하의 추천 기법에 대한 몇 가지 예를 몽구스로 보여주십시오. –
예제는 제공된 링크에서 찾을 수 있습니다. http://docs.mongodb.org/manual/reference/operator/update/push/#examples –