Mongo更新当前数据,重用数据集中的字段
我的数据集在数据库中是完整的;但是我想在数据库中的每个文档上创建一个新字段。我想通过我的一些输入以及数据库中当前的其他字段导出这个新字段:
IE:
Document:
{
"_id":myId,
"city":"fooville",
"state":"bar"
}
然后我想获取并迭代每个条目并添加如下内容:
Document:
{
"_id":myId,
"city":"fooville",
"state":"bar",
"cityState":"fooville, bar"
}
有没有一种简单的方法可以做到这一点?尝试避免重新插入整个数据集。
预先感谢您的帮助
(Mongo 很棒)
My dataset is complete in the DB; however I want to create a new field on each of the documents in the db. This new field I want to be derived by some of my input along with other fields that are currently in the database:
IE:
Document:
{
"_id":myId,
"city":"fooville",
"state":"bar"
}
Then I want to take and iterate through every entry and add something like this:
Document:
{
"_id":myId,
"city":"fooville",
"state":"bar",
"cityState":"fooville, bar"
}
Is there an easy way to do this? Trying to avoid re-inserting the entire dataset.
Thank you in advance for your help
(Mongo is awesome)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的事情:
我还没有测试过......但它应该有效......
Something like this:
I haven't tested it....but it should work...