为什么流星从今天开始在 _id 字段周围添加 ObjectId? [英] Why is meteor adding ObjectId around the _id field since today?

查看:47
本文介绍了为什么流星从今天开始在 _id 字段周围添加 ObjectId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我完全错了,但是由于我今天开始的项目,当我使用meteor mongo直接连接到mongodb,并插入一条记录(使用mycol.insert(..)时,_id字段被ObjectId包围(12345555...").从代码添加记录时,情况并非如此.因此,应用程序内不再识别通过 Meteor Mongo 添加的记录.我过去经常这样做......这里发生了什么?

Maybe I'm completely wrong, but since projects that I start today, when I use meteor mongo to connect directly to the mongodb, and insert a record (with mycol.insert(..) the _id field is surrounded with ObjectId("12345555..."). When adding a record from code this is not the case. So, records added via Meteor Mongo are not recognised inside the app any longer. I have done this in the past so often... what's happening here?

推荐答案

这就是 MONGO 的方式,您看到这一点是因为您使用的是 Mongo shell.Meteor 默认使用不同的方法(参见下文),您在以编程方式使用它时会看到这种方法.在 new Mongo.Collection

That's the MONGO way and you see this because you are using the Mongo shell. Meteor defaults to a different method (cf below) which you see when you use it programmatically. Check Meteor docs on new Mongo.Collection

idGeneration 字符串

生成这个集合中新文档的_id字段的方法.可能的值:

The method of generating the _id fields of new documents in this collection. Possible values:

  • 'STRING':随机字符串
  • 'MONGO':随机 Mongo.ObjectID 值

默认的 id 生成技术是 'STRING'

The default id generation technique is 'STRING'

在 Meteor 中,如果你写

In Meteor, if you write

Steffo = new Meteor.Collection("steffo", {idGeneration: 'STRING'});

这将导致条目

{ "foo" : "bar", "_id" : "68FWFNGRAuRt82pWy" }

如果你使用

Paul = new Meteor.Collection("paul", {idGeneration: 'MONGO'});

你会得到

{ "foo" : "bar", "_id" : ObjectId("26cfdb5f200adfa0b55a50d3" }

当您使用 Mongo shell 时会发生后者.

The latter happens when you use Mongo shell.

这篇关于为什么流星从今天开始在 _id 字段周围添加 ObjectId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆