은 불가능하지만, 다음과 같이 MongoDB를 당신은 데이터를 변환 할 수 있습니다
//find posts has array of objects
db.getCollection('posts').find({'_tags.0': {$exists: true}}).forEach(function (post) {
var items = [];
var property = '_tags';
post[property].forEach(function(element){
if(element._id !== undefined){
items.push(element._id);
}
});
if(items.length>0){
post[property] = items;
db.posts.update({_id:post._id},post);
}
});
소스 문서 :
{
"_id" : ObjectId("576aa0389863482f64051c81"),
"id_post" : 130155,
"_tags" : [
{
"_id" : ObjectId("576a9efd9863482f64000044")
},
{
"_id" : ObjectId("576a9efd9863482f6400004b")
},
{
"_id" : ObjectId("576a9efd9863482f64000052")
},
{
"_id" : ObjectId("576a9efd9863482f6400005a")
}
]
}
최종 문서 :
{
"_id" : ObjectId("576aa0389863482f64051c81"),
"id_post" : 130155,
"_tags" : [
ObjectId("576a9efd9863482f64000044"),
ObjectId("576a9efd9863482f6400004b"),
ObjectId("576a9efd9863482f64000052"),
ObjectId("576a9efd9863482f6400005a")
]
}
가 그것을 가능하다 이 문제에 대한 도움을 청하십시오. 그 정말로 나의 마지막 희망! –
안녕하세요, 데이비드, 네, 저에게 이메일을 보내 주시기 바랍니다. –