2017-09-01 137 views
0

我想將一個id字段添加到集合中,編號從1開始。 例如, 有一個收集的文章: MongoDB:如何將一個`id`字段添加到集合中?

{"_id" : ObjectId("98r498jfgragaja9ra4"),"titile":"foo","content":"foo..."} 
{"_id" : ObjectId("498aut89auhgua4940q"),"titile":"bar","content":"bar..."} 
{"_id" : ObjectId("30ua9ah984yhtauiga9"),"titile":"hello","content":"hello..."} 

加入id後場

,結果是這樣的:

{"_id" : ObjectId("98r498jfgragaja9ra4"),"titile":"foo","content":"foo...","id":"1"} 
{"_id" : ObjectId("498aut89auhgua4940q"),"titile":"bar","content":"bar...","id":"2"} 
{"_id" : ObjectId("30ua9ah984yhtauiga9"),"titile":"hello","content":"hello...","id":"3"} 

怎麼辦呢?

+0

您需要向我們展示了到目前爲止你已經嘗試什麼,即使它不工作... – Roberto

回答

相關問題