[英]How to insert an array as a new document after the .aggregation in mongodb?
我想在 MongoDB 中的聚合操作后插入一個 var object 作為新文檔。 我試試這個方法:
var postUpvote = db.collection.aggregation([
{$limit:1}
]).toArray()
db.collection.aggregation([
...
...
]).insert(postUpvote[0])
但是 db.collection.aggregation(...).instert() 不是 function。 第二個聚合結果只是一個文檔。 而且我還嘗試使用 $addFields 將 postUpvote 插入到文檔中,但是我無法將此插入的文件從文檔中取出到新文檔中。
{
"_id" : 1671,
"CommentUserId" : 1671,
"CommentUserUpVote" : 2644,
"PostUserId" : 1671,
"PostUserVote" : 2644
}
PostUserId 和 PostUserVote 是 var postUpvote。 我想要的結果是
{
"_id" : 1671,
"CommentUserId" : 1671,
"CommentUserUpVote" : 2644,
}
{
"_id": //Whatever, I don't care
"PostUserId" : 1671,
"PostUserVote" : 2644
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.