mongodb

MongoDB RegEx not working

淺唱寂寞╮ 提交于 2021-02-05 09:40:45
问题 I'm trying to return documents that whose obsNum field starts with 1. . I have written the following RegEx to filter out those documents however, it returns all the documents that start with 1 Observations.getObservationsModelObject().find({ "ageGroup": ageGroup, "obsNum": { $regex: '^\s*1\.' } }, function(err, foundData) {}); What am I doing wrong? This RegEx '^\s*1\.' is returning the following instead of returning on 1.3, 1.1 & 1.2: obsNum: 1.3 obsNum: 1.1 obsNum: 1.2 obsNum: 123 obsNum:

docker-compose java application connection to mongodb

佐手、 提交于 2021-02-05 09:37:20
问题 2 Containers, one Java application and the second mongodb. If I run my java app locally and mongodb in a container, it connects but if both run inside a container, java app can't connect to mongodb. docker-compose file is as follows, am I missing something version: "3" services: user: image: jboss/wildfly container_name: "user" restart: always ports: - 8081:8080 - 65194:65193 volumes: - ./User/target/User.war:/opt/jboss/wildfly/standalone/deployments/User.war environment: - JAVA_OPTS=

MongoDB Mongoose select documents between a date range

做~自己de王妃 提交于 2021-02-05 09:32:29
问题 I've a collection called events . Sample document is like this. I want to select documents with in date range of '2019-01-11' to '2019-11-27' . What I've done is this. But this seems not working. How do I achieve this using MongoDB Mongoose ? $match: { createdAt: { $gte: { $dayOfYear: '2019-01-11' }, $lte: { $dayOfYear: '2019-11-27' } } } 回答1: Use the Date() object instead. I am not sure if this affects the timezone as well. db.collection.find({ "createdAt": { "$gte": new Date('2019, 1, 11'),

How can I connect with X509 by putting all options in the connection string in node.js driver for mongodb?

白昼怎懂夜的黑 提交于 2021-02-05 09:20:07
问题 I'm using the keys available in mongodb docs for a self-signed certificate using X509 authentication with a Node.js Driver. When trying to connect to the database I get the following error: MongoNetworkError: failed to connect to server [pedro.com:57040] on first connect [MongoNetworkError: unable to verify the first certificate] Despite that error, I am sure that the connection works as I am using Studio 3T and everything is up and running by using the same certificates. So my question is...

Kubernetes statefulset with NFS persistent volume

梦想与她 提交于 2021-02-05 08:46:08
问题 I have a kubernetes cluster and I have a simple deployment for mongodb with NFS persistent volume set. It works fine, but since resources like databases are stateful I thought of using Statefulset for the mongodb , but now the problem is, when I go through the documentation, statefulset has volumeClaimTemplates instead of volumes (in deployments). But now the problem comes. in a deployment do it like this: PersistentVolume -> PersistentVolumeClaim -> Deployment But how can we do this in

MongoDB Project Array Document Size with Condition

微笑、不失礼 提交于 2021-02-05 08:36:05
问题 Let's say I have the following document structure: { "_id": "ID", "array": [ { "a": "A", "b": "B", "c": { "x": true, "y": true, "z": false } }, { "a": "A", "b": "B" }, { "a": "A", "b": "B" "c": { "s": true } } ] } I am trying to do an aggregation which gives me this type of output: { "_id": "ID", "array": [ { "a": "A", "b": "B", "c": 2 }, { "a": "A", "b": "B", "c": 0 }, { "a": "A", "b": "B" "c": 1 } ] } So what I want to do is to, instead of the document c , return the number of elements with

Unable to resolve promise rejection and send array as response

守給你的承諾、 提交于 2021-02-05 08:23:26
问题 I am trying to handle two queries within each other. exports.get_users = (req, res) => { SubscriptionPlan.find() .then((result) => { if (!result) { return res.status(400).json({ message: "unable to process" }); } let modifiedData = []; result.forEach(async (data) => { if (data.processStatus === "active") { await Users.findById(data.userId).then( (response) => { console.log(response) modifiedData.push(response); res.json(modifiedData) } ); } }); }) .catch((err) => console.log(err)); }; My

Update or append to a subcollection in mongo

狂风中的少年 提交于 2021-02-05 08:17:26
问题 I have a collection containing a subcollection. In one request, I would like to update a record in the subcollection or append to it if a match doesn't exist. For a bonus point I would also like this update to be a merge rather than an overwrite. A crude example: // Schema { subColl: [ { name: String, value: Number, other: Number, }, ]; } // Existing record { _id : 123, subColl: [ {name: 'John', value: 10, other: 20} ] } // example const update = { _id: 123, name: 'John', other: 1000 }; const

MongoDB filter objects array content based on object member

自闭症网瘾萝莉.ら 提交于 2021-02-05 08:15:27
问题 I have the following objects array and was wondering if there is a way to filter results as return only QtyIn records or return only QtyOut records? Any hint is highly appreciated. Thanks for your help { warehouseID: "1234", transactions : [ { "qtyIn" : "10", "transDateTime" : ISODate("2019-09-10T18:54:41.983Z") }, { "qtyOut" : "11", "transDateTime" : ISODate("2019-08-10T18:54:41.983Z") }, { "qtyOut" : "200", "transDateTime" : ISODate("2019-02-10T11:54:41.983Z") } ], } 回答1: You can compare

mongo-go-driver: nested OR/AND query filter

╄→гoц情女王★ 提交于 2021-02-05 08:15:26
问题 I try to create a MongoDB query filter with the nested operators (OR/AND/...). But lib requires to create a bson.D and pass bson.E elements into it. If I need to have OR/AND inside AND/OR - I need to put bson.M + bson.D inside bson.D like this: filter := bson.M{"$and": bson.D{{"p", 10}, bson.M{"$or": bson.D{{"s", 30}, {"a", 1}}}}} .. and of course it doesn't work: cannot use primitive.M literal (type primitive.M) as type primitive.E in slice literal . Probably the same problem will happen if