mongodb

MongoDB indexing for a Parse Server application

醉酒当歌 提交于 2021-02-08 03:38:11
问题 We have a social app where users can chat with each other and we’ve reached 350K messages! We recently noticed that as the number of messages is growing, the find operations are getting slower! I believe the issue here is that the Message collection is not indexed. That’s what I want to do now! I found this piece of code at the MongoDB docs: db.comments.ensure_index(('discussion_id', 1)) This is my Message collection: { chatRoom: <Pointer>, user: <Pointer>, text: <String>, isSeen: <Bool> } So

How to exclude _id without including other fields using the aggregation framework

怎甘沉沦 提交于 2021-02-08 03:37:30
问题 I would like to get the result of an aggregation pipeline without the _id filed. I know this is possible if you provide explicitly other fields that will be the output of the projection. But, ¿how can I mimic the $projec in a find call? This is what I want ( No field explicitly included ): db.col.find({},{_id:0}) But in the aggregation framework seems to be impossible: db.col.aggregate([{'$project': {_id:0}}]) Error: Printing Stack Trace at printStackTrace (src/mongo/shell/utils.js:37:15) at

How to exclude _id without including other fields using the aggregation framework

别说谁变了你拦得住时间么 提交于 2021-02-08 03:36:54
问题 I would like to get the result of an aggregation pipeline without the _id filed. I know this is possible if you provide explicitly other fields that will be the output of the projection. But, ¿how can I mimic the $projec in a find call? This is what I want ( No field explicitly included ): db.col.find({},{_id:0}) But in the aggregation framework seems to be impossible: db.col.aggregate([{'$project': {_id:0}}]) Error: Printing Stack Trace at printStackTrace (src/mongo/shell/utils.js:37:15) at

MongoDB $lookup on one document's array of object

感情迁移 提交于 2021-02-08 03:31:18
问题 I have searched online but could not find any match my case. Here is the situation. I am using aggregate to combine one collection and one document which is from another collection together restaurants.aggregate([ { $match: { _id: { $in: idList } } }, { $lookup: { from: "tags", localField: "details.restaurantType", foreignField: "details.restaurantType._id", as: "types" } }, { $project: { restaurantName: "$details.restaurantName", restaurantType: "$details.restaurantType", type: { $filter: {

How/where/when do I must call to MongoClient close?

廉价感情. 提交于 2021-02-08 03:02:56
问题 I am developing a web application in java and I have a doubt about closing MongoClient. Seeing this http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/#getting-started-with-java-driver The MongoClient instance actually represents a pool of connections to the database; you will only need one instance of class MongoClient even with multiple threads. See the concurrency doc page for more information. The MongoClient class is designed to be thread safe and shared among

redis

☆樱花仙子☆ 提交于 2021-02-08 02:40:07
一。基本概念 Redis和MongoDB是当前使用最广泛的NoSQL,而就Redis技术而言,它的性能十分优越,可以支持每秒十几万此的读/写操作,其性能远超数据库,并且还支持集群、分布式、主从同步等配置,原则上可以无限扩展,让更多的数据存储在内存中,更让人欣慰的是它还支持一定的事务能力,这保证了高并发的场景下数据的安全和一致性。它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型) 二。redis安装 $ wget http://download.redis.io/releases/redis-5.0.4.tar.gz $ tar xzf redis-5.0.4.tar.gz $ cd redis-5.0.4 $ make $ make install 在服务器端启动redis-server 在内置的客户端启动redis-cli 客户端进行测试: 客户端关闭服务器 三。redis常用数据类型和命令 redis中所有的数据都是通过键值对的方式存储的,即key:value。key是字符串类型的,value可以是字符串,hash,list,set,sortedset 1.字符串类型(key:string) 1.添加key:value set key value 2

How to update MongoDb database in Java?

佐手、 提交于 2021-02-07 21:35:26
问题 I'm newbie with the MongoDb, there are a lot of examples about updating a collection in 2.x versions but I couldn't find any source about 3.x versions. JAVA CODE: MongoClient mongoClient = new MongoClient("localhost",27017); MongoDatabase database = mongoClient.getDatabase("dbTest"); MongoCollection<Document> collection = database.getCollection("colTest"); Document updateQuery = new Document(); updateQuery.append("$set", new Document().append("_id", "test")); Document searchQuery = new

PHP MongoDB $set using arrayFilters

不想你离开。 提交于 2021-02-07 20:29:57
问题 I'm trying to update the value of "position" in "attributes" using the $ set operator with arrayFilters. The command below works as expected on the terminal db.produtos.insert( { "_id": 1, "nome":"Nome do Produto", "descricao":"Lorem ipsum dolor sit amet.", "atributos": [ { "id" : 1, "posicao" : 2 }, { "id" : 2, "posicao" : 1 }, { "id" : 3, "posicao" : 3 } ] } ) db.produtos.update( {"_id": 1 }, { $set: { "atributos.$[elem1].posicao": 1, "atributos.$[elem2].posicao": 2, "atributos.$[elem3]

Insert and return ID of sub-document in MongoDB document sub-document array

强颜欢笑 提交于 2021-02-07 20:18:42
问题 My node.js application will insert a sub-document into a nested sub-document array field of the following MongoDB document, and I need to determine the ID of the newly inserted sub-document: { "_id" : ObjectId("578d5a52cc13117022e09def"), "name" : "Grade 5 - Section A", "scores" : [{ "studentId" : ObjectId("5776bd36ffc8227405d364d2"), "performance" : [{ "_id" : ObjectId("57969b8fc164a21c20698261"), "subjectId" : ObjectId("577694ecbf6f3a781759c54a"), "score" : 86, "maximum" : 100, "grade" : "B

MongoDB no space left on device with docker

爷,独闯天下 提交于 2021-02-07 20:15:52
问题 My MongoDB gets stuck and returning the following error: 2019-01-28T18:28:53.419+0000 E STORAGE [WTCheckpointThread] WiredTiger error (28) [1548700133:419188][1:0x7feecb0ae700], file:WiredTiger.wt, WT_SESSION.checkpoint: /data/db/WiredTiger.turtle.set: handle-open: open: No space left on device 2019-01-28T18:28:53.419+0000 E STORAGE [WTCheckpointThread] WiredTiger error (22) [1548700133:419251][1:0x7feecb0ae700], file:WiredTiger.wt, WT_SESSION.checkpoint: WiredTiger.wt: the checkpoint failed,