mongodb

【MongoDB】用Docker安装一个MongoDB最新版玩玩

落花浮王杯 提交于 2021-02-17 01:02:18
1 安装 本文假设大家已经安装好了 docker 并能正常使用,所以不讲解如何安装 docker 了。用 docker 安装 MongoDB 最新版本如下: # 从repository查找mongo的相关镜像,结果很多,其中第一条为官方的镜像 $ docker search mongo # 下载官方镜像的最新版本 $ docker pull mongo:latest # 完成后,检查是否下载成功 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos 7 5e35e350aded 12 days ago 203MB mongo latest 965553e202a4 3 weeks ago 363MB hello-world latest fce289e99eb9 10 months ago 1.84kB 仅需要简单几个命令,我们就拥有了MongoDB的最新镜像了,后续就可以使用了。 2 启动 完成MongoDB的镜像下载后,启动就非常简单了,一个命令即可: $ docker run -itd --name mongo -p 27017:27017 mongo --auth 305ebd8236678905d16dd76e75dcf99fdd812be6b13c240acece7985d29b316c (1) -

MongoDB : Sorting Data when using DBcollection find

笑着哭i 提交于 2021-02-16 06:37:52
问题 I want to return the results from the find query with the help of sortaing based on lastUpdated field . Currently i have seen two ways First Approach BasicDBObject query = new BasicDBObject(); query.put("updated_at","-1"); query.put(MONGO_ATTR_SYMBOL, "" + symbol); DBCursor cursor = DBcollection.find(query).sort(query); Second Approach DBCursor cursor = DBcollection.find(query,new BasicDBObject("sort", new BasicDBObject("lastUpdated ", -1))); What is the best option to work with any ideas ??

MongoDB : Sorting Data when using DBcollection find

不打扰是莪最后的温柔 提交于 2021-02-16 06:37:20
问题 I want to return the results from the find query with the help of sortaing based on lastUpdated field . Currently i have seen two ways First Approach BasicDBObject query = new BasicDBObject(); query.put("updated_at","-1"); query.put(MONGO_ATTR_SYMBOL, "" + symbol); DBCursor cursor = DBcollection.find(query).sort(query); Second Approach DBCursor cursor = DBcollection.find(query,new BasicDBObject("sort", new BasicDBObject("lastUpdated ", -1))); What is the best option to work with any ideas ??

MongoDB : Sorting Data when using DBcollection find

时光总嘲笑我的痴心妄想 提交于 2021-02-16 06:36:48
问题 I want to return the results from the find query with the help of sortaing based on lastUpdated field . Currently i have seen two ways First Approach BasicDBObject query = new BasicDBObject(); query.put("updated_at","-1"); query.put(MONGO_ATTR_SYMBOL, "" + symbol); DBCursor cursor = DBcollection.find(query).sort(query); Second Approach DBCursor cursor = DBcollection.find(query,new BasicDBObject("sort", new BasicDBObject("lastUpdated ", -1))); What is the best option to work with any ideas ??

MongoDB in PHP - How do I insert items into an array in a collection?

假装没事ソ 提交于 2021-02-15 11:58:13
问题 This has to be easy, but i can't seem to figure it out... Let say i had a collection users and this is the first item in the collection: { "_id" : ObjectId("4d8653c027d02a6437bc89ca"), "name" : "Oscar Godson", "email" : "oscargodson@xxx.com", "password" : "xxxxxx", "tasks" : [ { "task" : "pick up stuff", "comment" : "the one stuff over there" }, { "task" : "do more stuff", "comment" : "lots and lots of stuff" } ] } How with the PHP driver for MongoDB would I then go and add another "task" to

MongoDB in PHP - How do I insert items into an array in a collection?

别说谁变了你拦得住时间么 提交于 2021-02-15 11:57:38
问题 This has to be easy, but i can't seem to figure it out... Let say i had a collection users and this is the first item in the collection: { "_id" : ObjectId("4d8653c027d02a6437bc89ca"), "name" : "Oscar Godson", "email" : "oscargodson@xxx.com", "password" : "xxxxxx", "tasks" : [ { "task" : "pick up stuff", "comment" : "the one stuff over there" }, { "task" : "do more stuff", "comment" : "lots and lots of stuff" } ] } How with the PHP driver for MongoDB would I then go and add another "task" to

How to populate nested entities in mongoose?

三世轮回 提交于 2021-02-15 11:03:36
问题 I have the following mongoose schema structure userSchema = new Schema({ roles: [ role: {type: Schema.Types.ObjectId, ref: 'Role' } ] }) rolesSchema = new Schema({ name: String, roleEntities: [ { entity : {type: Schema.Types.ObjectId, ref: 'RoleEntity' }, abilities : [{type: Schema.Types.ObjectId, ref: 'Ability' }] } ] } roleEntitiesSchema = new Schema({ name: String }) abilitiesSchema = new Schema({ name: String }) How can i populate all these nested documents while doing a find on the USER

How to populate nested entities in mongoose?

喜欢而已 提交于 2021-02-15 11:02:55
问题 I have the following mongoose schema structure userSchema = new Schema({ roles: [ role: {type: Schema.Types.ObjectId, ref: 'Role' } ] }) rolesSchema = new Schema({ name: String, roleEntities: [ { entity : {type: Schema.Types.ObjectId, ref: 'RoleEntity' }, abilities : [{type: Schema.Types.ObjectId, ref: 'Ability' }] } ] } roleEntitiesSchema = new Schema({ name: String }) abilitiesSchema = new Schema({ name: String }) How can i populate all these nested documents while doing a find on the USER

MongoDB 基础命令 (MongoDB Shell)

余生长醉 提交于 2021-02-15 09:53:48
1、我们 mongodb 安装成功后,用上一篇的方法启动 mongodb服务 然后使用 mongodb shell 来做数据库的增删改查 2、创建数据库 语法: use 数据库名称 案例: > use juyou switched to db juyou > show dbs admin 0 .000GB config 0 .000GB local 0 .000GB 这时创建完成过,使用命令查询数据库却没有我们刚创建的数据库,这时因为刚创建的数据库没有数据,下面我们在数据库中插入一条数据 > db.juyou.insert({ " name " : " 聚优福利 " }) WriteResult({ " nInserted " : 1 }) > show dbs admin 0 .000GB config 0 .000GB juyou 0 .000GB local 0 .000GB 这时就能看到刚刚创建的数据库了 3、删除数据库 语法: db.dropDatabase() 案例: 首先我们先查询一下所有的数据库 > show dbs admin 0 .000GB config 0 .000GB juyou 0 .000GB local 0 .000GB 然后我们可以使用 db 来查看当前的数据库 > db juyou 当前链接的数据库就是 juyou,如果不是可以使用 use

Insert large record into mongodb using mongo shell

我的未来我决定 提交于 2021-02-15 07:50:55
问题 I'm trying to insert large polygon array into my collection. I'm using following command to insert the data... db.geoPolygonData.insert({"polygonName":"location1", "polygons":{"type":"Polygon", coordinates:[[[ 17.60083012593064, 78.18557739257812], [ 17.16834652544664, 78.19381713867188], [ 17.17490690610013, 78.739013671875], [ 17.613919673106714, 78.73489379882812],[ 17.60083012593064, 78.18557739257812]]]}}); WriteResult({ "nInserted" : 1 }) Problem: when the polygon array size is too