I have a huge MongoDB collection with over 5 million documents. Every time I try to add a new document, I need to check if there is already a document with the same title in the collection before inserting it. For example, let's say this is my MongoD ...
I am currently working on fetching data within a specified price range from the property model. For example, if a user provides a minimum and maximum price, I want to display the number of properties that fall within that price range. I have indexed the ...
I'm trying to filter data by year in MongoDB based on a specific year and month. For example, if I pass in the year 2022, I only want to see data from that year. However, when I try using the $gte and $lte tags, it returns empty results. Can someone g ...
In the 'users' collection, I have a document with the following data: { "_id" : "388179687996974", "matches" : [ { "userId" : "1495728740672094", "choice" : false, "dates" : [], "d ...
Criteria: COUNT the total number of documents in the collection WHERE objects.objectType is 'group' AND (objects.objectType is NOT 'person' AND relation is 'Exposed_to') Expectation: should return the count of all documents WHERE objects.objectType is 'gr ...
I have created a schema as shown below: var UserSchema = new Schema({ firstName: { type: String, required: true }, lastName: { type: String, required: true }, email: { type: String, required: true }, location: { type: String, required: true }, p ...
app.get('/admin/reservas/:param', function(req, res) { var param = req.param("param"); console.log(param); mongoose.model('Something').findOne( { id: param }, function(err, obj) { ...
Below are the schemas for two different collections. var activitySchema = new Schema({ activity_id: {type: String, index: {unique: true}, required: true}, begin_date : String, ... }) var registrationSchema = new Schema({ activit ...
Need help with updating specific fields in a Mongoose driver and Express JS setup. Here is the schema: var mongoose = require('mongoose'), Schema = mongoose.Schema; var ProfilesSchema = new Schema({ presentRound: { type: Numb ...
When attempting to update multiple documents using a query generated from an object array, I encountered an issue where only one document was actually modified. var split = num.toString().split(','); var list = new Array; for ( var i in split ) { var ...
I'm currently developing a NodeJS application using Mongoose for database operations. Initially, I had no issues accessing my records in the "bears" database when authentication was disabled in Mongoose. However, upon enabling authentication and configuri ...
As a beginner in programming, I am putting in my best effort to figure things out on my own. However, I seem to be stuck without any guidance. I am attempting to display all products from the mongoDB based on their brand. While I have successfully set up a ...
Suppose I have a document with the following structure: { selectedId: ObjectId("57b5fb2d7b41dde99009bc75"), children: [ {_id: ObjectId("57b5fb2d7b41dde99009bc75"), val: 10}, {_id: ObjectId("57b5fb2d7b41dde99009bc75"), val: 20}, ...
When using aggregate in node.js, my code looks like this: collection.aggregate( { $group : { _id : "$id_page", "count" : {$sum : 1} } }, {$sort : {"count" : -1}}, {$limit : 1} ).limit(1).toArray(f ...
Let's say I have a users collection with the following documents: { _id: 1, hobbies: ['eat', 'read', 'swim'] }, { _id: 2, hobbies: ['eat', 'sl ...
I need help with handling this JSON data structure: { data : { fields_data : [ [ { key1 : val }, { key1 : val } ], [ { key2 : val }, { key2 : val ...
I'm currently facing an issue with returning the appropriate records for a given date query in MongoDB and Mongoose. Despite my efforts, all rows are being returned instead. Below, you'll find the relevant code snippet as well as the model schema. Please ...
I need to remove all entries in the infrastructure collection with a type.primary of "pipelines" and a type.secondary of "oil." Currently, I'm using this query: db.infrastructure.deleteMany({$and: [{"properties.type.primary": "pipelines&quo ...
My Collection is structured as follows: { id: 23423-dsfsdf-32423, name: Proj1, services: [ { id:sdfs-24423-sdf, name:P1_Service1, products:[{},{},{}] }, { id:sdfs-24jhh ...
Within my collection, there is an example document structured as follows: { "_id" : ObjectId("5bbb299f06229dddbaab553b"), "phone" : "+38 (031) 231-23-21", "date_call" : "2018-10-08", "adress_delivery" : "1", "quantity_concrete" : "1", ...
Seeking guidance on fetching and summing up the values of the "caseCount" objects within a schema. Can anyone provide me with assistance in accomplishing this task? Feel free to ask for further details if needed. Thank you! This is the Schema: const Profi ...
I currently possess the following assortment: { "_id" : ObjectId("5acdb95d5ea63a27c1facf92"), "venue" : ObjectId("5acdb95d5ea63a27c1facf8c"), "author" : ObjectId("5ac8ba3582c2345af70d4658"), } { "_id" : ObjectId("5acdb95d5ea63a27c1facf93") ...
I have a MongoDB schema that looks like this. { userID: 19202, products: [{ id: 020, name: 'first' }] } My goal is to remove items from the product array based on their id. I tried using the following command but it didn't give any errors and also ...
content of the document is provided below chatid:121212, messages:[ { msg:'Hello', time:'2021-04-17T16:35:25.879Z' }, . . . ] I am looking to retrieve all records where the timestamp is earlier than a ...
I have a Node.js API called /create/appointment that performs two operations: STEP 1: Checking for an active appointment in the database. STEP 2: Creating an appointment if it does not exist. There are three collections: doctors patients appointments ...
I have a collection that I need to export every 5 minutes based on the timestamp field. When querying the collection, the maximum date is as follows: db.testcol.find({},{_id : 0,ts : 1}).sort({ts:-1}) 2017-04-14 23:40:27.690Z I converted it to mil ...
Within my collection, there are various documents that store information about individuals: { name : 'Peter' city : 'New York' dogs_owned : 2, cats_owned : 1, } { name : 'Amir' city : 'Chicago' } { name : 'James' city : 'Chi ...
issue TS2339: The property 'user' is not found on the type 'Object'. export class UserAuthentication implements OnInit { user = new BehaviorSubject<Userlogin>(null); constructor( private route: ActivatedRoute, private rou ...
In my mongoose query, I am facing an issue where I need to select all rows except for specific ids. Here is a snippet of my code: var ids = [{id: 123},{id: 222},{id:333}]; User.find({_id: {$ne: ids.id }},'firstName lastName _id avatar',function (err,us ...
I currently have 3 blog posts stored in my MongoDB database and I am looking to retrieve a specific blog post based on its name. Here is an example of how the data is structured: [ { _id: ObjectId("61de0e1562abb7ffd4089373"), name: 'le ...
Here is an array containing objects: item1 = { name:'item', val:1, list:[ {type:'a',value:1}, {type:'b',value:1}, {type:'c',value:1} ] }; item2 = { name:'item', val:5, list:[ ...
I am attempting to increase the value of a specific element in my array object "options": [ { "key": "banana", "votes": 0 }, { "key": "apple", "votes": 0 }, { "key": "mango", "votes": 0 ...
People Database: [ { "_id": ObjectId("5f3258cfbaaccedaa5dd2c96"), "gender": "male", "name": { "title": "mr", "first": "victor", " ...
My goal is to query the database for documents and if a certain field is not set, I want to replace it with a custom value. Let's say I have a collection of songs in my database where some have 'pathToCover' set and some don't. In those cases where it's no ...
I have a field within my collection that looks like this: uniqueId: 123 inTarefa: true exclude: "ab,cd," orderId: 987 I am attempting to update all of the values using a "FindOneAndUpdate" query like so: collection.findOneAndUpdate({ 'uniqu ...