- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于 grails 的 MongoDB id 的问题。我在域类中使用了字符串 id,它会在域类中创建字符串 id,这很好。但是当我手动在 mongodb 中插入条目时(运行 db.Things.insert()),它会为新条目创建一个 ObjectId(不是字符串),我想知道我们如何解决这个问题。
谢谢!
最佳答案
引用来自:Mongo Collections - Reference Documentation
By default in GORM entities are supplied with an integer-based identifier. So for example the following entity: class Person {} Has a property called id of type java.lang.Long. In this case GORM for Mongo will generate a sequence based identifier using the technique described in the Mongo documentation on Atomic operations.
However, sequence based integer identifiers are not ideal for environments that require sharding (one of the nicer features of Mongo). Hence it is generally advised to use either String based ids:
class Person { String id } Or a native BSON ObjectId:
import org.bson.types.ObjectId class Person { ObjectId id }
BSON ObjectId instances are generated in a similar fashion to UUIDs.
关于MongoDB Grails 插件 ObjectId V.S.字符串编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15479105/
假设我在文件开头有这个定义: const ObjectId = mongoose.Types.ObjectId; 您更喜欢哪一个,为什么? // 1 new ObjectId; // 2 new O
我通过以下两种不同的方法生成了一个 ObjectId: user@ubuntu:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
我编写了一个 Python 代码,用于从名为 Tweets 的 Mongo 集合中获取推文。我不想只获取对象文本并添加一个名为 Sentiment 的附加对象。 当我循环推文并将 json 对象解析为
我是 Node.js 和 mongodb 的新手。 在我的 Node.js 应用程序中,我使用的是 mongodb,对于 mongodb 操作,我使用的是 mongoose。 在 package.js
使用 parse.com 和 JavaScript SDK。 这就是我想要实现的目标。 页面上将用户( friend )列表返回给用户,然后他们可以单击其中一个用户,页面将更新以列出所有该用户的项目(
我有一个像这样的 objectId:["56153e4c2040efa61b4e267f","56033932efefe0d8657bbd9e"]为了在我的模型中保存该信息,我使用: items: [
我有一个标签模式: const TagSchema = new Schema({ label: {type: String, unique: true, minlength: 2}, upda
在online API他们指的是 Mongo::ObjectID。 我有 require 'mongo' 但 ruby 仍然找不到它。例如,我需要通过它的 Id 找到一个对象,我正在做: mong
作为管道的最后阶段,我有一个像这样的 $project : { ... anId : new ObjectId() } 但是 mongo 为每个文档生成相同的 Id。我希望它为每个投影文档生成
我需要在这样的数组中找到 mongoose objectID 的索引: [ { _id: 58676b0a27b3782b92066ab6, score: 0 }, { _id: 58676aca
我们可以从客户端生成 ObjectId 并在插入时使用它。我确实希望它在插入过程之外进行处理。我需要将其配置为我的默认 _id 生成过程,以便当我调用 insert 时,insert 方法应该创建自定
这是代码。跟随者和追随者无法工作。换句话说,我无法将像 {"user1", objectId1} 这样的对象推送到这两个数组。是否允许有一个字段同时包含对象 ID 和字符串名称?感谢您的帮助。 The
为什么 Meteor.js 使用它自己的 IDsp 算法> 为什么不使用 MongoDB ObjectId()? 最佳答案 如果你选择使用 Meteor,它对对象 ID 使用相同的方法: Meteor
Mongoose 菜鸟问题:我有两个 Mongoose ObjectId 对象列表,我将它们合并为一个。有些 ObjectId 是重复的,我不想将它们保存到我的数据库中。是否有 Mongoose 工具
以下代码从供应商集合中的员工数组中提取员工 await new VendorManager() .update( { emplo
我有一个简单的模型对象: class UserRating include MongoMapper::EmbeddedDocument key :idea_id, ObjectId key
谁能告诉我使用 #[objectId] 或 [id=objectId] 引用元素有什么区别? 最佳答案 第一个非常快,因为 jQuery 内部使用 getElementById当它识别出模式时(使用正
我的架构是: var schema = new Schema({ players: { type: [Schema.Types.ObjectId]}); 我正在使用 promi
这似乎是这样定义我的架构: var PossessionSchema = new mongoose.Schema({ thing: {type: mongoose.Schema.Types.Obj
我想要解决的是:使用建议的方法(mapReduce)保留 $in 中的 Id 数组的顺序: Does MongoDB's $in clause guarantee order 我已经完成了我的作业,发
我是一名优秀的程序员,十分优秀!