如何在MongoDB中设置主键? [英] How to set a primary key in MongoDB?

查看:410
本文介绍了如何在MongoDB中设置主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将我的一个字段设置为主键.我正在使用 MongoDB 作为我的NoSQL.

I want to set one of my fields as primary key. I am using MongoDB as my NoSQL.

推荐答案

_id字段为mongodb中的主键保留,该字段应为唯一值.如果未将任何内容设置为_id,它将自动用"MongoDB Id对象"填充它.但是您可以在该字段中输入任何唯一信息.

_id field is reserved for primary key in mongodb, and that should be a unique value. If you don't set anything to _id it will automatically fill it with "MongoDB Id Object". But you can put any unique info into that field.

其他信息: http://www.mongodb.org/display/DOCS/BSON

希望有帮助.

这篇关于如何在MongoDB中设置主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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