[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Restore mongodb standalone and tags: []

[User]
Text:Hi All,We have lost data in collection documents, before 13th July, we have these files in /data/db  dir how can we recover it usng /data/db dir, we checked  all other  dir, /var we didnt find any WT except in /data/db dir… below files present in /data/dbHow can we restore  with old data before 13th July  in collections, we don’t have current backup present at the moment.
Code:collection-0--1930030124829508624.wt
collection-0--5138667409853774933.wt
collection-0--7067830708941503295.wt
collection-0--7947847146613003270.wt
collection-12--5138667409853774933.wt
diagnostic.data/
index-1--1930030124829508624.wt
index-1--7067830708941503295.wt
index-10--5138667409853774933.wt
mongod.lock
journal/
sizeStorer.wt
sizeStorer.wt.1
storage.bson
WiredTiger
WiredTiger.lock
WiredTiger.turtle
WiredTiger.wt
WiredTiger.wt.orig
WiredTigerLAS.wt

[Assistant]
Text:How can we restore with old data before 13th July in collections, we don’t have current backup present at the moment.To do a restore you first need a backup.  A filesystem snapshot is good enough.
Code:

[Assistant]
Text:By your own words you don’t have a backup, ergo you cannot restore.  You would need the database file at the point before you lost your data.The files you have for your standalone database represent the database as it is now or when you shut it down.
Code:

[User]
Text:Thanks Chris for feedback.We have checked with our dba team they are suggesting all the collection and index files before 13th july are present in /data/db dir…whcih i have shared above.Suppose if  DBAs are telling correctly that all the files before 13th july are present in /data/db dir, how can we restore it any methods.Current senerio is i checked the collections by taking latest mongodump in standalone db and checked in one db collection documents are present after 13th july to sysdata in collection files.Any suggestion would be great help, we need to recover the old data before 13th july, what steps we have to  follow.We checked all the files before shut down, no WT files  found except /data/db dir.
Code:

[Assistant]
Text:We have checked with our dba team they are suggesting all the collection and index files before 13th july are present in /data/db dir…whcih i have shared above.So there was a backup and they have given you files?  Why would your dba team not just do the recovery for you, that is a dba’s role.We have checked with our dba team they are suggesting all the collection and index files before 13th july are present in /data/db dir…whcih i have shared above.Then you should be able to start mongod using /data/db for the --dbpath option(this is the default anyway).Current senerio is i checked the collections by taking latest mongodump in standalone db and checked in one db collection documents are present after 13th july to sysdata in collection files.If the data is not there, then you need files from further back.
Code:--dbpath

[User]
Text:le to start mongod using /data/db for the --Thanks Chris for the feedback.We  have standlone db in prod, and we are planning to  run this steps  to restore mongodb old data before 13th July data.taken mongodump backup of all dbs using mongodump commandtake backup of current  collection and index  WT files present in data/db dir.As dba team suggest us all files present in /data/db dir before 13th July also
Will run the command after  backups :
mongod --dbpath /data/dbnow if suppose db is not coming up, what should we do .
and also we have question we dont have any test and dev env setup so will do run these commands in prod db only.we  need suggestions  the data which is present in /data/db dir from 13th july to till date if suppose restore happens from mongod --dbpath /data/db   command will  current data will mismatch , is there any conflicts in data can occur.for all these  please suggest, thanks.
Code:--

[Assistant]
Text:Hi @bp_sinI would be very cautious in your scenario. I strongly recommend you take a backup of your production database and test all outcomes in a separate environment first. If this is critical production data to restore and your team doesn’t have the in-house expertise, I would consider hiring a consultant for assistance.If I understand your situation correctly:The last step is the most complicated: unless collections of interest happen to be insert only, there may be conflicts between the current data and the data as of a month ago. You will have to work out how to reconcile any differences. Restoring older data will also include data that has been intentionally removed at a later date.My suggested approach would be:we dont have any test and dev env setup so will do run these commands in prod db only.Unless your production data is not essential, I would take the time to set up a test environment.Regards,
Stennie
Code:dbPathmongodmongodmongodump --querymongorestore

[User]
Text:Thanks Stennie,Could you please assist from WT  collection and index files present in /data/db dir , how to restore the old data.
is we can use mongod --dbpath /data/db command to restore , before that will take the backup using mongodump and current backup of all files present inn /data/db dir.for test env creation can we  keep all this /data/db dir fles in our local system where i have installed mongo in  dir: /data/ and restart mongod to test.
Code:

[Assistant]
Text:Could you please assist from WT collection and index files present in /data/db dir , how to restore the old data.Hi @bp_sin,If you follow my suggested approach above, the first step is making sure you have a viable file copy backup:If these files are a viable backup copy, mongod --dbpath /path/to/your/backup should start without any errors relating to data files and you will be able to query to confirm if the data you are looking for is present.If the WT files you have are not a consistent backup, your options are unfortunately limited. You can try repairing or salvaging data as a last resort but that is often unsuccessful (see: Recover corrupted files (MongoDB 3.0.12) .wt - #4 by Stennie).for test env creation can we keep all this /data/db dir fles in our local system where i have installed mongo in dir: /data/ and restart mongod to test.You should have separate paths for data files belonging to different backups or environments. Mixing files from different deployments may result in an unusable deployment.I’d still recommend engaging a consultant (or your DBA team, if there is someone with more MongoDB admin experience on the team) as incorrect manipulation of data files or merging of data could lead to further challenges.Regards,
Stennie
Code:mongodmongod --dbpath /path/to/your/backup

[User]
Text:Thanks Stennie for feedback.My approach am trying please suggest is it correct:any other steps you would like to provide which  i can test in my local system, thanks.Or any other files  i also need to copy apart from all the files  from prod in /data/db dir.
to setup and test.
Code:

[User]
Text:Thanks Stennie,I have run in my local system   by copying all the WT files from /data/db to /data/backup_restore and run the command mongod --dbpath /data/backup_restore, it’s still running from last 3 hours.Could you please suggest if any files missing or corrupt files present in /data/db dir how can we restore  the data before july 13 old data.any suggestions.
Code:

[User]
Text:If the data is not there, then you need files from further back.Thanks Chris,If  suppose some of files are missing before 13th july in /data/db dir in prod env, can we still restore the rest of data present before 13th july in WT collection and index files in /data/db dir
using commandmongod --dbpath /data/dbhow can we approach to test env first,Can you please suggestWhat  are the steps to be follow in test env to replicate this senerios.We have no data before 13th July in standalone db, DBA team  updating all datafiles are present in /data/db dir in prod env, if there statmenet is correct then can we restore the old data directly in prod.I have installed mongodb in my local system, if want to replicate the prod senerio my approach below:-
Code:

[Assistant]
Text:I have run in my local system by copying all the WT files from /data/db to /data/backup_restore and run the command mongod --dbpath /data/backup_restore, it’s still running from last 3 hours.Hi @bp_sin,mongod is the primary daemon process for MongoDB. On startup, mongod will verify the integrity of files in the dbpath but I wouldn’t expect this to take 3 hours for the 5 collections you have listed in your earlier output.What is the last output from mongod? It may have started up successfully and be waiting for connections.Running mongod with an older backup of your data files will allow you to query and potentially mongodump relevant data. This is not doing any sort of “restore” process: you have to do that manually and reconcile any differences between your two environments.Could you please suggest if any files missing or corrupt files present in /data/db dir how can we restore the data before july 13 old data.There should be startup errors if data files are missing or have checksum issues.Are you working on this issue with anyone from your DBA team? As I mentioned earlier, this procedure would benefit from assistance from someone with more MongoDB admin experience.Regards,
Stennie
Code:mongodmongoddbpathmongodmongodmongodump

[User]
Text:Thanks Stennie,
Our DBA replying with:
We should take backup.
I’m not sure that the data was actually deleted or not.
We’ve found that mongodb pod cannot access to data then tried to restore them July 16th . During that process we’ve taken a backup.
have no idea what kind of operation happened for production after that.
create new DB or overwrite them?Could you please provide steps  how will we create new mongodb.
Code:

[User]
Text:How can we restore  the old data from these files present in /data/db dir.
Code:

[Assistant]
Text:Hi @bp_sin,Have you tried starting up a mongod instance with your backup copy of this dbPath as mentioned earlier?If mongod is able to start successfully, you can query and export data using standard tools like the mongo shell and mongodump. Assuming the data you are looking for is present, try to follow the general guide I suggested earlier in this discussion.If mongod has any issues reading the data files, there should be warnings logged on startup with more context on files that are missing or problematic. If you don’t have a viable backup copy, your options are limited and unlikely to be fully successful (see Recover corrupted files (MongoDB 3.0.12) .wt - #4 by Stennie, which Chris mentioned earlier).The specific steps involved require an understanding of the data you are trying to recover and ideally someone who is working through the process with you directly (i.e. a MongoDB expert from your DBA team or an external consultant).Regards,
Stennie
Code:mongoddbPathmongod --dbpath /path/to/your/backup
mongodmongomongodumpmongod

[User]
Text:HI Stennie, thanks for suggestion.
I tried copying all the  files from /data/db dir of production db and restored into my local system where mongodb is installed, and kept in the dir: E:\restore_backup
and tried  running mongo with commandmongod --dbpath E:\restore_backupbut it’s still runing from last 6 hours.any suggestions, thanks
Code:C:\Program Files\MongoDB\Server\5.0\bin>mongod --dbpath E:\restore_backup
{"t":{"$date":"2021-08-20T23:57:04.308+05:30"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2021-08-20T23:57:05.559+05:30"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-08-20T23:57:05.559+05:30"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-08-21T08:42:57.939+05:30"},"s":"I",  "c":"CONTROL",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
{"t":{"$date":"2021-08-21T08:42:58.313+05:30"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"E:/restore_backup/diagnostic.data"}}
{"t":{"$date":"2021-08-21T08:42:58.320+05:30"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"127.0.0.1"}}
{"t":{"$date":"2021-08-21T08:42:58.320+05:30"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}

[Assistant]
Text:Waiting for connectionsYour mongod is running in foreground
Just open another cmd prompt and connect to your mongod with mongo
Code:

[User]
Text:Thanks Ramachandra,Getting below error:
Code:C:\Program Files\MongoDB\Server\5.0\bin>mongo
MongoDB shell version v5.0.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect@src/mongo/shell/mongo.js:372:17
@(connect):2:6
exception: connect failed
exiting with code 1


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Exceeded memory limit for $group, but didn't allow external sort and tags: ['aggregation', 'atlas']

[User]
Text:I have an issue when execute query have group and sort for large data about 15 thousand record
“Exceeded memory limit for $group, but didn’t allow external sort. Pass allowDiskUse: true to opt-in.”
this is an error that I’m facing, and I’m trying to use {allowDiskUse: true} but it didn’t work
How I can fix it?
note: I’m using Shared Clusters for development environments and low-traffic applications M2
Code:

[Assistant]
Text:Hello @Walaa_Medhat, welcome to the MongoDB Community forum!The usage of the aggregate option allowDiskUse is not supported on the shared M2 Cluster configuration of Atlas. See Atlas M0, M2 and M5 tier limitations, which says:Atlas Free Tier and shared clusters do not support the allowDiskUse option for the aggregation command or its helper method.
Code:allowDiskUseallowDiskUse

[User]
Text:Oops, So if Use M10 it’ll work well?
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Get the latest record from each group and tags: ['aggregation']

[User]
Text:Given a collection of documentsWith millions of documents that look like these:Return the latest document for each combination of features., within a time window (updated_at after certain date and before a later date)There are a limited number of feat1,feat2,feat3 combinations (e.g. 10000), but many entries for each such combination (1000s).I tried an aggregate query with this pipelineHowever mongodb fails complaining the data set does not fit in memory, or takes forever (literally) to return a resultI tried various indices on the data such asto no avail.I tried to add a limit to the backward search such aswhich helped some, however, once I accumulated more data it stopped working again.Any ideas how to solve this will be greatly appreciated.
Code:{
 feat1:"string",
 feat2:"string",
 feat3:"string",
 val1:"number",
 val2:"number",
 val3:"number",
 updated_at:ISODate()
};
[
{feat1:"a",feat2:"A1",feat3:"A1-1",val1:5,val2:7,val3:3,updated_at:ISODate("2021-08-140T00:00:01z")},
{feat1:"b",feat2:"B3",feat3:"B3-77",val1:i15,val2:0,val3:9,updated_at:ISODate("2021-08-14T00:01:30z")},
{feat1:"a",feat2:"A5",feat3:"ABBB",val1:3,val2:17,val3:2,updated_at:ISODate("2021-08-14T00:03:39z")},
 ...
];
 [
    {"$sort": {"updated_at": -1}},
    {"$group": {
      "_id": {"feat1": "$feat1", "feat2": "$feat2", "feat3": "$feat3"},
      "feat1": {"$first": "$feat1"},
      "feat2": {"$first": "$feat2"},
      "feat3": {"$first": "$feat3"},
      "val1": {"$first": "$val1"},
      "val2": {"$first": "$val2"},
      "val3": {"$first": "$val3"},
      "updated_at": {"$first": "$updated_at"}
    }},
    {"$project": {
      "_id": 0, "feat1":1, "feat2": 1, "feat3": 1,
      "val1":1, "val2": 1, "val3": 1, "updated_at": 1
    }}
  ]
 {"key": {"_updated_at":-1}},
 {"key": {"feat1": 1,"feat2": 1,"feat3": 1}},
 {"key": {"_updated_at":-1, "feat1": 1,"feat2": 1,"feat3": 1}},
 {"key": {"feat1": 1,"feat2": 1,"feat3": 1, "_updated_at":-1}},
  {"$match": { /* Consider the last 30 hours (108000000) of data */
    "$expr": {"$gt": [
      "$_updated_at",
      {"$subtract": [ {"$max": "$updated_at"}, 108000000]}
    ]}
  }},

[Assistant]
Text:Hello @Gilad_Odinak, you can use the allowDiskUse aggregate option to overcome memory restriction during sort and group stages. You can try this option and see how it works and if you are getting the desired result.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Introduce yourself and tags: []

[User]
Text:Hi all,I am George and I am from Romania. Been looking forward to this class for a while now Bests!
Code:

[Assistant]
Text:Hey! Ulises, from Guatemala. Excited to get my hands on MongoDB
Code:

[Assistant]
Text:Hello everybody ,
I am Akash Deep , from India. I am excited to explore  NoSQL with Mongo.Happy Coding.
Code:

[Assistant]
Text:Greetings everyone, I’m Brad, however I prefer to be called Joseph. I just hate my first name.Anyhow, I’m originally from the United States, however I live in China, I work as an ESL (English as a Second Language) teacher. What I’m hoping to get out of this is to at least learn the basics of Databases because I would like to hopefully have the stepping stones of being a Junior Full Stack developer. And maybe sometime later I’ll take additional courses here to further my career.Anyhow, pleasure to meet everyone
Code:

[Assistant]
Text:Hi everyone. I’m Ramil. I’m originally from Azerbaijan, but currently I work and live in Czech Republic. I’m primarily work as an Oracle DBA, and new database systems are interesting for me, therefore I decided to start learning MongoDB.
Code:

[Assistant]
Text:Hi,
I’m Jason. Looking forward to learning more about MongoDB and learning from everyone here.
Good luck
Code:

[Assistant]
Text:Hi
I am Ralf from Germany. working as DBA. Just want to have a look on MongoDB.
Code:

[Assistant]
Text:Hi everyone,
I’m Samia. I’m moroccan and I’m living in Paris. I want to learn more about noSQL with Mongodb.
Nice to meet you all
Code:

[Assistant]
Text:Hello, Im Josue from Mexico, hope everyone can learn all the necessary of MongoDB.
Code:

[Assistant]
Text:Hi everybody.
I’m Dwayne, from the United States.  I work as a Data Analyst primarily with Amazon Redshift and PostgrSQL, and I’m excited to learn more about Mongo and NoSQL!
Code:

[Assistant]
Text:Hello, I’m a Patricio, I’m an engineer in computer science, I hope to make the most of this learning opportunity.
Code:

[Assistant]
Text:Hello, I’m Jacob hope everyone does well and learns a lot!
Code:

[Assistant]
Text:Hi folks,
My name is Stan. I’m a Canadian   and I live in Toronto. I work in the Big data field and was exploring MongoDB when I came across this course.
I really like the fact that this course is self-paced with an acknowledgment certificate on successful completion.
All the best .
Code:

[Assistant]
Text:Hello community,
I am Babar from Pakistan currently working as a Software Engineer (Java) for a Software House catering health sector. I was excited to learn more about NoSQL databases after intro with IBM cloudant that’s why I enrolled myself in this course.
Code:

[Assistant]
Text:Hello everyone,I am Kanika from Gurgaon, India. I will be your TA, I hope I could help everywhere I can.Really Happy to see you all so excited. I really wish you guys Good Luck with this course and have fun with MongoDB.Happy Leaning! Kanika
Code:

[Assistant]
Text:Hi everyone,
I am Denys from Ukraine. I’m working react.js developer. I want to learn more about MongoDB.
Good luck, all!
Code:

[Assistant]
Text:Hi everyone, I’m Hoang Ngo - an iOS developer from Vietnam. Recently I tried to write some API by NodeJS and MongoDB by myself, I enrolled in this course for better knowledge of MongoDB and NoSQL databases.
Code:

[Assistant]
Text:Morning from Spain, I’m Ignacio
Code:

[Assistant]
Text:Hello Everyone,I am Deepika from India. I am very exited to learn MONGO DB.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Could not start MongoDB 5.0 running Oracle Linux on VirtualBox and tags: ['installation']

[User]
Text:Hi All,I am new to MongoDB. What I do I follow the installation guide to install MongoDBUsing tarball. My OS is Oracle Linux 8.4After completed installationI started
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.logand always got “illegal instruction (core dumped)”I dont know how to check it, and there is no log too and not sure why coredump.Can you advise where to check and how to fix it?Appreciated . Thanks
Code:

[Assistant]
Text:May be it is a permissions issue
mongodb is unable to access dbpath & logpath directories
Does the owner of mongod have read/write privs on these dirsFor test purpse you can change db & log path to some other dir like your home dir and check
Code:

[Assistant]
Text:Welcome to the MongoDB Community Forums @Dinh_Hoang !An illegal instruction error suggests that you are running a binary which is not supported by your CPU.Can you confirm:Regards,
Stennie
Code:

[User]
Text:Thanks for reply.I change dir again and start it but it is still the sameI am using Oracle Linux 8.4 on Virtual Box, It is x86-64 bitsI downloaded Linux redhat/CentOS 8.0. Is it correct bin?Thanks for your help
Code:[mongod@localhost ~]$ ls -lrt
total 0
drwxrwxr-x. 2 mongod mongod  6 Aug 21 09:03 mongo
drwxrwxr-x. 3 mongod mongod 21 Aug 21 09:03 log
[mongod@localhost ~]$ ls -lrt /home/mongod/log/mongodb/
total 0
[mongod@localhost ~]$ ls -lrt /home/mongod/mongo
total 0
[mongod@localhost ~]$ mongod --dbpath /home/mongod/mongo --logpath /home/mongod/log/mongodb/mongod.log
Illegal instruction (core dumped)
[mongod@localhost ~]$

[User]
Text:Just add in more detail for OS
Code:   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ff3df1686a26409199f9686b0646ca6a
           Boot ID: 88496d361dad421e9d1e11113f9559f6
    Virtualization: oracle
  Operating System: Oracle Linux Server 8.4
       CPE OS Name: cpe:/o:oracle:linux:8:4:server
            Kernel: Linux 5.4.17-2102.201.3.el8uek.x86_64
      Architecture: x86-64

[User]
Text:Hi All,I downloaded 4.4 and it works, I am not sure why latest version 5.0.2 did not work for Oracle Linux 8.4Have a nice day!Thanks
Code:

[Assistant]
Text:Hi @Dinh_Hoang,This is likely related to changes in 5.0.cat /proc/cpuinfo has many of the details to look this up.
Code:cat /proc/cpuinfo

[Assistant]
Text:Hi @Dinh_Hoang ,Can you provide the output of /proc/cpuinfo as @chris suggested?The likely reason for encountering an illegal instruction is that your CPU does not meet the x86_64 microarchitecture requirements for MongoDB 5.0.Regards,
Stennie
Code:/proc/cpuinfo

[User]
Text:Hi Chris and Stennie,Here is my infoThere is 4 cores , So it should be a “Sandy Bridge* or later Core processor”
therefore I am confusing why It did not work for MongoDB 5Thanks
Code:processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 142
model name      : Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
stepping        : 10
microcode       : 0xffffffff
cpu MHz         : 1895.999
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni ssse3 cx16 pcid sse4_1 sse4_2 hypervisor lahf_lm invpcid_single pti fsgsbase invpcid md_clear flush_l1d arch_capabilities
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 3791.99
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

[User]
Text:I found the noteMongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK).It could be I am using kernel UEK, but how to check and confirm it?
Code:

[User]
Text:#uname -a
Linux localhost.localdomain 5.4.17-2102.201.3.el8uek.x86_64 #2 SMP Fri Apr 23 09:05:57 PDT 2021 x86_64 x86_64 x86_64 GNU/LinuxIt is EUK kernel but it works for 4.4 not 5.0.2, It is strange
Code:

[Assistant]
Text:Hi @Dinh_Hoang,Your Core i5-8350U CPU looks like it should have the right feature support, but your /proc/cpuinfo output is missing AVX extensions.Can you confirm:It looks like there are a few conditions for AVX support in VirtualBox:Normally Hyper-V blocks Virtualbox. Hyper-V is a type-1 hypervisor, which accesses the hardware first before any OS runs, and therefore interferes with other programs that need “virtualization technology”, like Virtualbox, which is a type-2 Hypervisor.Regards,
Stennie
Code:/proc/cpuinfo


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Case Insensitive Search with Regex and tags: ['atlas-functions']

[User]
Text:I am trying to do a case-insensitive search using Regex - the documentation gives examples with literal strings but I am trying this using a variable instead. This search works but only with matching case - how can I make it case insensitive?
Code:exports=function (payload) {

  const query={"dt_name" : {'$regex':"^"+payload.query.testparam.toString()+"$"}};
  const mongodb=context.services.get("mongodb-atlas");
  const mycollection = mongodb.db("dt3_api").collection("LCP Production");

return mycollection.find(query).limit(10).toArray();
};

[Assistant]
Text:Hello! @Richard_Kaplan .By adding the i option in the regex pattern to perform a case-insensitive match for documents:e.gdb.collection.find({name:{'$regex' : '^string$', '$options' : 'i'}})More info: https://docs.atlas.mongodb.com/schema-suggestions/case-insensitive-regex/Hope this helps
Code:idb.collection.find({name:{'$regex' : '^string$', '$options' : 'i'}})

[User]
Text:@HomAskIeThank you - that works if I literally hard code a stringWhat is the syntax if the string is in a variable - specifically a parameter from the URL i.e. payload.query.testparam
Code:

[User]
Text:I tried this and various similar configurations:return mycollection.find ({ "dt_name": { '$regex' : new RegExp(param1, $options:'i') }   });But I get:“error”: “(BadValue) $regex has to be a string”
Code:return mycollection.find ({ "dt_name": { '$regex' : new RegExp(param1, $options:'i') }   });

[Assistant]
Text:Ah I see. $regex expects the pattern to be a string or an expression. If you’d like to use RegExp then you need to convert it to string.You code might become:You can include insensitive within RegExp too.The ignoreCase accessor property indicates whether or not the i flag is used with the regular expression.then it might becomenotice there is an “i” right after param1.Hope this helps. Thank you
Code:$regexreturn mycollection.find ({"dt_name": { '$regex' : new RegExp(param1).toString(), $options: 'i' } });
return mycollection.find ({"dt_name": { '$regex' : new RegExp(param1, "i").toString()} });

[User]
Text:return mycollection.find ({"dt_name": { '$regex' : new RegExp(param1, "i").toString()} });Much appreciatedI get no error now, but the result of the find is always blank with either syntax.  Even if I replace param1 with the desired parameter in quotes the find is always blank.However this more simplified version does work - but only as a case-sensitive search: return mycollection.find ({"dt_name":param1});How do I get it to work not as a case-sensitive search?
Code:return mycollection.find ({"dt_name": { '$regex' : new RegExp(param1, "i").toString()} }); return mycollection.find ({"dt_name":param1});

[Assistant]
Text:hum… interesting. Could you share with me some sample of your data?
Code:

[User]
Text:See private message… thanks
Code:

[Assistant]
Text:I’m not 100% sure why that’s not working for you because It works for me.What is the value of param1 look like?Try to make a loop to log each doc after before return see what is the output.
Something like:
Code:param1data = mycollection.find ({"dt_name": { '$regex' : new RegExp("Kaplan", "i").toString()} });
// or
// data = mycollection.find ({"dt_name": { '$regex' : 'Kaplan', "$options": "i" } });
for (const d of data) {
    console.log(d);
}
return data

[User]
Text:You can see param1 as testparam in Postman - It is currently set as Kaplan and I am hoping for it to work  with both Kaplan and kaplanYour proposed code as a Realm function yields this:
image754×158 19.2 KB
Realm looks like this:
image1135×670 77.3 KB

Code:

[Assistant]
Text:I see. Could you let me know which mongo driver you are using?Try this to see it work
Code:const param1 = "kaplan"  // You might change this to be dynamic from query string
const docs = mycollection.find({
    "dt_name": {
        "$regex": param1, "$options": "i"
    }
});
const data = await docs.toArray();
console.log("Doc Len", data.length);
return data;

[User]
Text:MongoDB 4.4.8That code in Realm gives me this error shown on top:
image1293×843 97.9 KB

Code:const param1 = "kaplan"  // You might change this to be dynamic from query string
const docs = mycollection.find({
    "dt_name": {
        "$regex": param1, "$options": "i"
    }
});
const data = await docs.toArray();
console.log("Doc Len", data.length);
return data;

[Assistant]
Text:Ah that’s on Realm Function Editor! My bad. Even I’m new to that tool as well ha haAll right, I just set up Realm and figure it out.
Try this simple way. It works for me on Ream as well.Have you tried this way?
Code:const docs = mycollection.find({
    "dt_name": {
        "$regex": param1,
        "$options": "i"
    }
});
return data;

[User]
Text:I think you meant const data instead of const docsYes it works that way!  Huge thanks!!!Can you explain why the other methods did not work?
Code:

[Assistant]
Text:Hi! I’ve been trying to make it works with RegExp on Realm but have not solved it yet.
It seems like the the slashes when convert a RegExp object to string is the problem.
e.g
This won’t work
Code:let pattern = new RegExp("abc").toString()
console.log(pattern);
"/abc/"


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Setting up MongoDB v5.0 on Ubuntu 20: "core-dump: STATUS 4/ILL" and tags: ['installation']

[User]
Text:I am trying to install and start a MongoDB on a fresh installation of Ubuntu 20 (it’s literally the first thing I did after sshing onto the server).I followed the setup tutorial and did the following steps:When I run sudo systemctl status mongod I get the following error:If I simply run mongod I get the following error:
Illegal instruction (core dumped)This is my configuration (unchanged after installing, located at /lib/systemd/system/mongod.service):I already checked the mongoDB-logs, it seems like MongoDB crashes before creating any logs at all because the folder is empty.I am not sure if that is normal but I looked for the environment file at /etc/default/mongod (see in config) but it doesn’t exist…I tried the following things to fix this error:Interesting to note might be that I once had a Mongo DB running on this server but I had to reset the server after completly deleting the /tmp and /var/log/ directories (yes I should have researched a little before doing this ). The MongoDB stopped working then but I am pretty sure that my server provider has reset everything of these previous versions of the server after I clicked reset and they reinstalled ubuntu (all of the other things are deleted as well).I am really stuck here, I hope someone has an idea because MongoDB is essential to the stuff I’m working on atm…
Code:sshcurl -fsSL https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.listsudo apt-get updatesudo apt-get -y install mongodb-orgsudo systemctl start mongodsudo systemctl status mongodmongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: failed (Result: core-dump) since Sun 2021-08-22 23:25:56 CEST; 2s ago
       Docs: https://docs.mongodb.org/manual
    Process: 86514 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dumped, signal=ILL)
   Main PID: 86514 (code=dumped, signal=ILL)

Aug 22 23:25:55 Ubuntu20-64Bit systemd[1]: Started MongoDB Database Server.
Aug 22 23:25:56 Ubuntu20-64Bit systemd[1]: mongod.service: Main process exited, code=dumped, status=4/ILL
Aug 22 23:25:56 Ubuntu20-64Bit systemd[1]: mongod.service: Failed with result 'core-dump'.
mongodIllegal instruction (core dumped)[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
/etc/default/mongodsystemctlsudo apt-get purge mongodb-org*/var/log/mongodb/var/lib/mongodbmongomongodb/tmp/var/log/

[Assistant]
Text:Welcome to the MongoDB Community Forums @Philipp_Kolbe !The likely reason for encountering an illegal instruction is that your CPU does not meet the x86_64 microarchitecture requirements for MongoDB 5.0.Can you please:Related discussion for someone trying to run MongoDB 5.0 on VirtualBox: Could not start MongoDB 5.0 running Oracle Linux on VirtualBox.Thanks,
Stennie
Code:/proc/cpuinfo

[User]
Text:Here is the output of /proc/cpuinfo:processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 6
model name      : Common KVM processor
stepping        : 1
microcode       : 0x1
cpu MHz         : 2693.508
cache size      : 16384 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 sys>bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 5387.01
clflush size    : 64
cache_alignment : 128
address sizes   : 40 bits physical, 48 bits virtual
power management:(sorry if I didn’t format this correctly again , how can I edit my posts and how can I create these Code-Boxes?)Here are the requirements given by the server host:I reinstalled a different version of Ubuntu (18.04) but it didn’t work either…As I said, the DB was already working for months on this server so I don’t understand what would change after reinstalling Ubuntu.I am still waiting for further information of my server host, I hope you can already read something from this… I am quite sure that it is a VM though.Best regards,
Philipp
Code:/proc/cpuinfo

[Assistant]
Text:Hi @Philipp_Kolbe,Thanks for the further info. This is apparently a KVM environment with some host CPU features masked via the “Common KVM processor” virtualised CPU exposed to the VM.The host Xeon CPU may have the required features, but the VM’s CPU does not support instructions required by MongoDB 5.0 (such as AVX and SSE) which should be listed in the CPU flags:flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsrSome options to consider are:try installing the MongoDB 4.4 server packages (they target older CPU microarchitectures)upgrade your VM or hosting to support the required server extensionscompile MongoDB 5.0 from source using older architecture tags (this may be tricky given your virtual CPU seems to have limited instruction support)Regards,
Stennie
Code:flags

[User]
Text:Thanks alot! Installing MongoDB version 4.4.8 worked on Ubuntu 18.One more question… is it possible that the 4.4 version does not have a mongosh? When I’m running the command it tells me that it can’t find the mongosh command. Now I’m using mongo which is working. Is there a difference between the two?
Code:mongoshmongoshmongo

[User]
Text:Nevermind… I independetly installed sudo apt-get install mongodb-mongosh, now that’s working too.Again, thanks for the quick help…
Code:sudo apt-get install mongodb-mongosh

[Assistant]
Text:Hi @Philipp_Kolbe ,mongosh is a modern replacement for the legacy mongo shell, and the recommended shell as of the MongoDB 5.0 release.For more information and feature highlights, see:Regards,
Stennie
Code:mongoshmongomongo


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Installing mongoDB issue on ubuntu 20.01 and tags: ['installation']

[User]
Text:I tried to install mongoDB in my OS so I followed these steps:
1- “wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -”
output2- “echo “deb MongoDB Repositories buster/mongodb-org/5.0 main” | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list”
output:3- after sudo apt-get update:
“sudo apt install mongodb-org”
output:4- “sudo apt --fix-broken install”
output:Sorry for this long post, but I’m really stuck since 2 days and I didn’t find any solution, plz help me
Code:pub   rsa4096 2021-02-16 [SC] [expires: 2026-02-15]
      F567 9A22 2C64 7C87 527C  2F8C B00A 0BD1 E2C6 3C11
uid           [ unknown] MongoDB 5.0 Release Signing Key <packaging@mongodb.com>
deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main
Reading package lists... Done
Building dependency tree
Reading state information... Done
mongodb-org is already the newest version (5.0.2).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 mongodb-org-database : Depends: mongodb-org-server but it is not going to be installed
                        Depends: mongodb-org-mongos but it is not going to be installed
 mongodb-org-tools : Depends: mongodb-database-tools but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libboost-program-options1.71.0 libgoogle-perftools4 libpcrecpp0v5 libtcmalloc-minimal4 libyaml-cpp0.6 mongo-tools mongodb-server-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  mongodb-database-tools mongodb-org-mongos mongodb-org-server
The following NEW packages will be installed:
  mongodb-database-tools mongodb-org-mongos mongodb-org-server
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
3 not fully installed or removed.
Need to get 0 B/91.1 MB of archives.
After this operation, 182 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 294599 files and directories currently installed.)
Preparing to unpack .../mongodb-org-server_5.0.2_amd64.deb ...
Unpacking mongodb-org-server (5.0.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_5.0.2_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_5.0.2_amd64.deb ...
Unpacking mongodb-org-mongos (5.0.2) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_5.0.2_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/mongos', which is also in package mongodb-server-core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-database-tools_100.5.0_amd64.deb ...
Unpacking mongodb-database-tools (100.5.0) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-database-tools_100.5.0_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/mongodb-org-server_5.0.2_amd64.deb
 /var/cache/apt/archives/mongodb-org-mongos_5.0.2_amd64.deb
 /var/cache/apt/archives/mongodb-database-tools_100.5.0_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

[Assistant]
Text:Hi @Moez_Ben_RebahIt looks like you have previously install mongodb from the ubuntu repositories which is generating this conflict.
You will have to uninstall those component first. See the following link to the documentation.
Code:

[User]
Text:Hi chris,
I already do that and now I get this error when I try to check my mongo availability with :output:I tried many solution such as:but mongodb still inactive
Code:sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2021-08-23 16:11:02 CET; 18s ago
       Docs: https://docs.mongodb.org/manual
    Process: 4671 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
   Main PID: 4671 (code=exited, status=14)

أوت 23 16:11:00 desktop systemd[1]: Started MongoDB Database Server.
أوت 23 16:11:02 desktop systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
أوت 23 16:11:02 desktop systemd[1]: mongod.service: Failed with result 'exit-code'.
sudo chown -R mongodb:mongodb /var/lib/mongodb
chown -R mongodb:mongodb /var/lib/mongodb

[User]
Text:Hi there,
I fix my issue, by uninstall and reinstall mongoDB
Code:

[Assistant]
Text:Hi @Moez_Ben_RebahGlad you got it installed, that detail is included in the troubleshooting link.If your output includes a mix of mongodb-org and mongodb binaries, you may need to first apt remove , apt purge , and apt autoremove the mongodb-org package before attempting to remove and purge the Ubuntu mongodb package. After clearing all MongoDB-related packages, retry the installation procedure.
Code:mongodb-orgmongodbapt removeapt purgeapt autoremovemongodb-orgmongodb


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How can update an item in a nested array, or add to the nested array if the item is not present? If there is no document create one and tags: ['crud', 'mongoose-odm']

[User]
Text:In my app, users create word lists. A user can change the order of words in each list, they can also change the order of each list.When a user creates or edits a list, the word list is updated.If word lists have already been created, the word list will be added to the existing word lists.If a word list has been edited (added words / removed words / word order changed) the existing word list will be updated.If word lists have not been created yet, then a new document should be added to the database.I found a solution, but it runs 2 findOneAndUpdate queries if a new word list is added. How can I achieve this with 1 query? Should I simplify my schema or change it so that it uses a nested object instead of an array?My word Lists schema:My 1 or 2 query solution:My attempted solution:Does not work. Can’t use $set and $setOnInsert with the same field.
Code:findOneAndUpdateconst wordListsSubSchema = new Schema({
  title: {
    type: String,
  },
  words: [
    {
      id: {
        type: String,
      },
      word: {
        type: String,
      },
    },
  ],
});

const WordListSchema = new Schema({
  wordLists: [wordListsSubSchema],
  user: {
    type: mongoose.Schema.ObjectId,
    ref: 'User',
    required: 'You must supply a user',
  },
});

exports.wordListAddorEdit = async (req, res) => {
  const listUpdate = await WordList.findOneAndUpdate(
    {
      user: req.user.id,
      'wordLists.title': req.body.wordList.title,
    },
    {
      $set: { 'wordLists.$.words': req.body.wordList.words },
    },
    {
      new: true,
      runValidators: true,
      useFindAndModify: false,
    }
  );

  if (listUpdate === null) {
    await WordList.findOneAndUpdate(
      {
        user: req.user.id,
      },
      {
        $addToSet: { wordLists: [req.body.wordList] },
      },
      {
        upsert: true,
        new: true,
        runValidators: true,
        useFindAndModify: false,
      }
    );
  }
  res.json('success');
};

exports.wordListAddorEditNOTWORKING = async (req, res) => {

  const list = await WordList.findOneAndUpdate(
    {
      user: req.user.id,
    },

    {
      $set: {
        wordLists: {
          $cond: {
            if: { $in: [req.body.wordList.title, '$wordLists.title'] },
            then: {
              $map: {
                input: '$wordLists',
                in: {
                  $mergeObjects: [
                    '$$this',
                    {
                      $cond: [
                        {
                          $eq: ['$$this.title', req.body.wordList.title],
                        },
                        { words: req.body.wordList.words },
                        {},
                      ],
                    },
                  ],
                },
              },
            },
            else: {
              $concatArrays: [
                { $ifNull: ['$wordLists', []] },
                [req.body.wordList],
              ],
            },
          },
        },
      },
      $setOnInsert: {
        wordLists: [req.body.wordList],
      },
    },

    {
      upsert: true,
      new: true,
      runValidators: true,
      useFindAndModify: false,
    }
  );
  res.json('success');
};

[Assistant]
Text:Hi @Matt,
I would create this schema:Then, use this:Btw, don’t forget to use try and catch clauses when using await db.collection.doSomething to handle cases of failure.Thanks,
Rafael,
Code:const wordListSchema = new Schema({
  user: {
    type: mongoose.Schema.ObjectId,
    ref: 'User',
    required: 'You must supply a user',
  },
  title: {
    type: String,
  },
  words: [
    {
      id: {
        type: String,
      },
      word: {
        type: String,
      },
    },
  ],
});
  await WordList.updateOne(
    {
      user: req.user.id,
      title: req.body.wordList.title,
    },
    {
      $set: { words: req.body.wordList.words },
    },
    {
      upsert: true,
      runValidators: true
    }
  );

[User]
Text:Thank you! The simpler schema makes it much easier.
I wrapped my controller in a catchErrors function to handle any errors. Thanks for your help.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How to remove a document from an array? and tags: ['crud', 'golang']

[User]
Text:Hi,
I already posted my db structure in another post HERE but I copy and paste everything here.These are my structs:This is my collection:I want to REMOVE the element with _id = 611efbb06986120738b4092f using mongo-go-driver.How can I do this?I read this post https://www.mongodb.com/community/forums/t/remove-array-element-in-mongodb-in-go/4831 but my case is different because my array is not a string array, but it contains documents.Thank you.
Code:type Home struct {
	ID         primitive.ObjectID `json:"id" bson:"_id"`
	Name       string             `json:"name" bson:"name"`
	Location   string             `json:"location" bson:"location"`
	Rooms      []Room             `json:"rooms" bson:"rooms"`
}

type Room struct {
	ID              primitive.ObjectID   `json:"id" bson:"_id"`
	Name            string               `json:"name" bson:"name"`
	Floor           int                  `json:"floor" bson:"floor"`
}
{
		"_id": "611ed1a7e81cf2e4879a73f8",
		"name":"blablabla",
		"location":"New York",
		"rooms":[
			{
				"_id":"611ed1a7e81cf2e4879a7399",
				"name":"test1",
				"floor":3
			},
			{
				"_id":"611efbb06986120738b4092f",
				"name":"test2",
				"floor":5
			}
		]
	}

[Assistant]
Text:Hi,
Try this (change it to something the mongodb go library can eat…):Thanks,
Rafael,
Code:db.collection.updateOne({_id: "611ed1a7e81cf2e4879a73f8"}, {$pull: {rooms: {_id: "611efbb06986120738b4092f"}}})


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Core dump on MongoDB 5.0 on RPi 4 and tags: ['server', 'installation']

[User]
Text:Hi all,I’m currently attempting to install a local MongoDB deployment with version 5.0, but am getting the following error when attempting to start the service:“mongod.service: Main process exited, code=dumped, status=4/ILL”Trying to just run “mongo” gives the error “Illegal instruction (core dumped)”.I’ve attached a picture of the fuller status when I take a peek at the service after attempting to start it. Currently I’m attempting to install this on a 64-bit installation of Ubuntu 20.04 on a raspberry pi 4. I’m able to successfully install 4.4.6 without issue, but 5.0 gives me the following:
error770×176 11.1 KB
It looks like it’s trying to point me to status code 4 here:However, trying to look around a bit more for this error code online doesn’t lead me to much. I get this error even when attempting a totally fresh install of 5.0 with no preexisting databases. I also have not changed the config file away from default.Thanks very much in advance! And apologies if this is in the wrong section of the forum. This is my first time posting here and I’ve tried to put it in the section that I thought was most relevant to the question.
Code:

[Assistant]
Text:Welcome to the MongoDB Community Forums @Heiaha !Can you check your MongoDB log file for more context leading up to the shutdown message (and share the relevant log lines)?Also, which Raspberry Pi 4 model do you have: 2, 4, or 8 GB RAM?Thanks,
Stennie
Code:

[Assistant]
Text:@Heiaha  Do you get any solution fot this issue? I also have this issue… i can’t get any solution yet…
Code:

[Assistant]
Text:Hi @ajay_ps,Are you also using MongoDB 5.0 on a Raspberry Pi 4? If not, please start a new topic with more details about your environment including specific your specific versions of MongoDB, O/S, and hardware architecture (eg arm64, x64, …). It would also be helpful to include any relevant log messages prior to the mongod process shutting down.If you definitely have a similar environment and might be encountering the same issue (for example, identical exit code), you could post a log snippet here to help correlate the issues.However, generally it is best to start a separate topic so we can focus on your issue rather than combining discussions that may be addressing different issues.Thanks,
Stennie
Code:mongod

[Assistant]
Text:I’m having the same issue
Raspberry Pi 4, 4GB RAM, 256GB SD card with Ubuntu 20.04

image793×234 17.1 KB

Code:

[User]
Text:Hi @Stennie_X. Sorry for the late response. While I have the log file set to the default value in the config file (/var/log/mongodb/mongod.log), that file appears to not exist. It may perhaps be the case that mongo crashes before creating a log during its first startup? The relevant directory (/var/log/mongodb/) appears to exist but is empty.Also, I am running on a Raspberry Pi 4 Model B with 4 GB RAM.Thanks!
Code:

[Assistant]
Text:@Stennie_X  I am using Mongo DB 5.0.0_amd64.deb
On ubuntu 20.04.2 LTS, OS type 64-bit , GNOME version 3.36.8, windowing system ×11 , processor -
Intel pentium (R) CPU G2010 @2.80GHZ×2,
4 GB ram.
Code:

[User]
Text:Just to be thorough, even though I don’t think it should matter much: I’ve replaced the Raspberry Pi stock micro SD with a larger Samsung EVO microSD and am running Ubuntu 20.04 instead of the stock Pi distribution.
Code:

[Assistant]
Text:That’s exactly what’s happening to me as well, that’s why I included the ls commands on my screenshot
This is a fresh, first time install, and it still doesn’t work…
Code:

[Assistant]
Text:Same here:
image1139×268 56.7 KB

Code:

[Assistant]
Text:Same here:
image784×188 18.7 KB

Code:

[Assistant]
Text:Hi Folks,I’ve tracked down this issue to a change in the arm64 microarchitecture requirements for MongoDB 5.0 packages. MongoDB 5.0 requires ARM v8.2-A or later and the Raspberry Pi 4 uses an ARM Cortex-A72 which is ARM v8-A.Unfortunately this means the pre-built packages for MongoDB 5.0 will not support Raspberry Pi 4.However, you should be able to build from source by adding CCFLAGS-march=armv8 to the SCons invocation. See Building MongoDB for full instructions.If building from source is a daunting prospect, an alternative would be to install the latest ARM 64 package of MongoDB 4.4.Regards,
Stennie
Code:arm64CCFLAGS-march=armv8

[User]
Text:Hi @Stennie_X,Ahh, that’s understandable. I think most RPi4 folks probably will have a hard time doing that if I’m reading the build guide correctly and 600 GB is required. Thanks very much for looking into this!
Code:

[Assistant]
Text:Hi @Heiaha,The large sizes are for debug builds. Stripped binaries (as shipped in the install packages) are much smaller. The strip utility can be used to remove debug info, but you will need some working space to compile. I would choose the most minimal SCons target you need, for example install-mongod.If you have access to a better resourced desktop machine you can cross-compile for RPi4. Instructions should be similar to cross-compiling MongoDB v4.4 but I don’t have an Rpi4 handy to test the build process or outcomes.Assuming your requirement isn’t to try out some of the new 5.0 features, the most straightforward path would be to install the pre-built MongoDB 4.4 packages Regards,
Stennie
Code:stripinstall-mongod

[Assistant]
Text:Please note that the native and cross-compilation instructions that @Stennie_X linked to already include the --separate-debug flag, which will already split out the debug symbols into separate files. So you will get reasonably sized binaries from those processes. You can shrink those binaries a little further yet with strip, but I don’t necessarily recommend this, as it will strip out symbol table information that will result in uninterpretable backtraces should the process crash, and the savings aren’t that big. You do still need a lot of storage space to actually build (and a lot of cores if you want reasonable build throughput), which is why I really commend going the cross-compile path if you can. The RPi just isn’t suited to building software of this size from source. The cross-compilation instructions aren’t particularly challenging, and you just need access to a reasonably performant x86_64 machine running Ubuntu to do it.
Code:--separate-debugstrip

[Assistant]
Text:I have the same situation here, RPi 4 with ubuntu and the exact error code. After installing MongoDB 4.4.8, works perfectly for me.Thank you, guys!
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Type is not assignable to type 'OptionalId<T>' and tags: ['node-js', 'crud', 'typescript']

[User]
Text:Any ideas?I’m trying to write a Typescript generic using the Nodejs driver v4.1.0. I was using the DefinitelyTyped types so I’m refactoring to bring everything up to speed.I have 3 type interfaces that extend the interface ICMDR. ICMDR is the one with _id.Attempting to do the following:ESLint is flagging it withArgument of type ‘T’ is not assignable to parameter of type ‘OptionalId’.
Type ‘ICMDR’ is not assignable to type ‘OptionalId’.ts(2345)Here’s the ICMDR:
Code:_idconst post = async <T extends ICMDR>(res: NextApiResponse, db: Db, cmdr: T) => {
  delete cmdr._id;
  await db.collection<T>('cmdrs').insertOne(cmdr);
};
export interface ICMDR {

  _id?: ObjectId; //from BSON

  cmdrName: string;

  discordName: string;

  discordJoinDate: Date;

  platform: Platform;

  rank: Rank;

  inaraLink?: string;

  region: Region;

  notes?: string;

  email?: string;

  isDeleted?: boolean;

}


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Golang. Insert mgo ObjectId via mongo driver and tags: ['crud', 'golang']

[User]
Text:We are migrating from mgo to mongo driver and we meet a problem with insert mgo/bson “bson.ObjectId” into MongoDB via mongo driver.For example, I have a struct:When I insert this struct in MongoDB, values have a type “string” and looks like this:Have anybody ever has the same problem?
Thanks in advance.
Code:type Default struct {
    ID bson.ObjectId `bson:"_id" json:"id"`
    UserID bson.ObjectId `bson:"user_id" json:"user_id"`
}
{
    "_id" : "a\u0016B\u001b�\u001cqGdt��",
    "user_id" : "a\u0016B\u001b�\u001cqGdt��"
}

[Assistant]
Text:What may be happening is you’re using structs that contain fields that are mgo bson.ObjectId type but using the mongo-go-driver BSON marshaler (inserting structs using the mongo-go-driver marshals the struct data as BSON). Because the mgo bson.ObjectId type is an alias of string, the bson.ObjectId fields are being marshaled as string.If my assumption about your use case is correct, you should replace the bson.ObjectId type with primitive.ObjectID from the "go.mongodb.org/mongo-driver/bson/primitive" package and see if that resolves the issue.E.g.Can you share a code snippet of how you’re using instances of the Default struct with the mongo-go-driver so I understand your use case better?
Code:bson.ObjectIdbson.ObjectIdstringbson.ObjectIdstringbson.ObjectIdprimitive.ObjectID"go.mongodb.org/mongo-driver/bson/primitive"type Default struct {
    ID     primitive.ObjectID `bson:"_id" json:"id"`
    UserID primitive.ObjectID `bson:"user_id" json:"user_id"`
}
Default


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Aggregate: Replacing an array of IDs with the corresponding objects from an array in the same document and tags: ['aggregation', 'node-js']

[User]
Text:I have the following documents in a collection:I now want to write a query to find the document with a specific container ID (i.e. container1) and return it, while transforming it’s selectedItems array to hold the actual object values from the items array of the same document.I want to get this document:Currently I have the following aggregation (Node.js):I know there is $lookup, but as I want to populate the matching array items from the same document (not a differect collection), I think I don’t need it. Even when specifying the same collection in a $lookup, it would populate the array with the root document of my collection and it would get very complex to unwind & match the needed properties of the subdocument.I thought about making an own items collection, but I would need slower lookups there and my data does not need to have these relations.I hope my question is clear, I’m thankful for any help I can get!I’m doing some additional transforms in my real data like copying some properties from the original root document and hiding others, but that should not matter.Thank you again!
Code:[{
	id: 1,
	name: 'My document 1',
    allItems: [{
        id: 'item1',
        name: 'My item 1'
    }, {
        id: 'item2',
        name: 'My item 2'
    }, {
        id: 'item3'
        name: 'My item 3'
    }],
    containers: [{
        id: 'container1',
        selectedItems: [
            'item3',
            'item1'
        ]
    }, {
        id: 'container2',
        selectedItems: [
            'item3'
        ]
    }]
},
...]
container1selectedItemsitems{
	id: 1,
	name: 'My document 1',
    container: {
        id: 'container1',
        selectedItems: [{
            id: 'item3'
            name: 'My item 3'
        }, {
            id: 'item1',
            name: 'My item 1'
        }
    }
}
db.collection.aggregate([{
    $match: {'containers.id': 'container1'},
    $addFields: {
        container: {
            $filter: {
                input: '$containers',
                as: 'container',
                cond: {
                    $eq: ['$$container.id', 'container1']
                }
            }
        }
    },
    $project: {containers: 0},
    $unwind: {path: '$container'}

    // I now have a new property "container" with the correct subdocument from the array
    // and removed the original array with all containers.
    // I now need a stage here to populate the container subdocuments in the `selectedItems` array

    $project: {allItems: 0} // remove the list of all items when not needed anymore in a following stage
}]);
$lookup$lookupitems

[Assistant]
Text:Hi @phe,You are definitely on the right track!I now want to write a query to find the document with a specific container ID (i.e. container1 ) and return it, while transforming it’s selectedItems array to hold the actual object values from the items array of the same document.As you already complete a similar process with your initial $addFields stage to find the container, all that needs to be done is to deconstruct the embedded array of container.selectedItems in order to match each individual item with its corresponding id found in container.selectedItems.So with saying that, I’ve broken the additional stages into two parts.Please note that the projection stage I’ve added removes the need for the two $project stages you have in your existing pipeline.I hope this helps Cheers,
Giuliano
Code:container1selectedItemsitems$addFieldscontainercontainer.selectedItemsidcontainer.selectedItemscontainer.selectedItemsselectedItemcontainerallItems{
    $unwind: {
        path: "$container.selectedItems",
    }
},
{
    $addFields: {
        "container.selectedItems": {
            $arrayElemAt: [
                {
                    $filter: {
                        input: "$allItems",
                        as: "item",
                        cond: { $eq: ["$$item.id", "$container.selectedItems"] },
                    },
                },
                0,
            ],
        },
    }
}
$project{
    $group: {
        _id: {
            doc: "$_id",
            container: "$container.id",
        },
        name: {
            $first: "$name",
        },
        selectedItems: {
            $push: "$container.selectedItems",
        },
    },
},
{
    $project: {
        _id: "$_id.doc",
        name: "$name",
        container: {
            id: "$_id.container",
            selectedItems: "$selectedItems",
        },
    },
}
$project


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How to convert primitive array into object array with key and value? and tags: ['aggregation', 'queries', 'node-js']

[User]
Text:Hi, i have an array like this
array: [0,1,2,4,5,7,86,4,32,3,4]
i need to assign a key to them all like the result will be:array: [{“key”: 0}, {“Key”:1},… so on to all.
by Aggregation only.
thanks
Code:

[Assistant]
Text:@Brutal_Jazzy, you can try this aggregation query. To convert the primitive element in the array field to an object, use the $map operator to iterate over the array field and transform each element (as needed).
Code:$mapdb.collection.aggregate([
{
  $addFields: {
      array: {
         $map: {
             input: "$array",
             as: "e",
             in: { key: "$$e" }
         }
      }
  }
},
])

[User]
Text:Thanks man it helped a lot. once last help needed.
let say the array has repeating values
[1, 1, 2, 3, 4, 5, 5, 6, 7]now i want to give two keys to each
[{item: 1
timesRepeated: 2}, so on]
how we do it?
Thanks a lot sir.
Code:

[Assistant]
Text:Here is the query for that.
Code:db.collection.aggregate([
{
  $unwind: "$array"
},
{
  $group: {
      _id: { _id: "$_id", a: "$a" },
      count: { $sum: 1 }
  }
},
{
  $sort: { _id: 1 }
},
{
  $group: {
      _id: "$_id._id",
      array: { $push: { item: "$_id.array", repeated: "$count" }}
  }
}
])

[User]
Text:Thanks again Sir,
Without using group and unwind?
something like this?{
atm: {
$map: {
input: ‘$am’,
as: ‘o’,
‘in’: {
a: ‘$$o’,
c: {
$cond: {
‘if’: {
or reduce here to count etc?
then: ‘N’,
‘else’: ‘P’
}
},
t: 0
}
}
}
}
Code:

[Assistant]
Text:@Brutal_Jazzy, I am afraid you have to try that yourself  . Also, please do post further questions you have as new posts.
Code:

[User]
Text:Kindly, i have tried at least 20 times in the last 24 hours i am stuck at this. i cannot use:
Sort and Unwind actually.
Code:

[Assistant]
Text:Please elaborate on the reasons whyi cannot use:
Sort and Unwind actually.
Code:

[User]
Text:Hi, because i have used sort too many times and it might over use Ram and give errors. as for the unwind my document is large and i have used unwind few times already and i will have to use group again.
I am thinking something like reduce.
Code:

[User]
Text:Sir i have added a new question which explains very well i am sorry for the disturbance please check this question out:
Code:

[User]
Text:please check this:
Code:

[Assistant]
Text:because i have used sort too many times and it might over use Ram and give errors. as for the unwind my document is large and i have used unwind few times already and i will have to use group again.
I am thinking something like reduce.You don’t need to use the sort stage in the query - the query will work the same. It is there so that the elements in the array are ordered.Have you tried the query? Do you have any errors when you run the query?Even if you use $reduce, it still requires the same kind of memory - it has to do the group and count (or even the sort) to calculate the output you are expecting. It is a stateful operation too (like the sort and the group are). Calculating sums, counts, averages, minimum, maximum, etc., are all some kind of reduction operations and are stateful (or blocking). They will need the RAM.
Code:$reduce

[User]
Text:your query run as charm there were no errors. but now i am trying to remove one step which adds the keys to the array elements please check my other question i will be thankful.
thanks
Code:

[User]
Text:the only problem this aggregate has it doesn’t copy the old values if you can add that to this query it is also fine with me. it gives me the single document which has the array and id but i have other fields in the previous document from which we use $unwind thanks
Code:

[Assistant]
Text:the only problem this aggregate has it doesn’t copy the old valuesNOTE:
Code:db.collection.aggregate([
{
  $unwind: "$a"
},
{
  $group: {
      _id: { _id: "$_id", a: "$a" },
      doc: { $first: "$$ROOT" },
      count: { $sum: 1 }
  }
},
{
  $group: {
      _id: "$_id._id",
      doc: { $first: "$doc" },
      a: { $push: { item: "$_id.a", repeated: "$count" }},
  }
},
{
  $addFields: {
      "doc.a": "$a"
  }
},
{
  $replaceWith: "$doc"
}
])
aarray$sort

[User]
Text:Great man thank you very very very very very very much. May you have many many more knowledge and keep helping others.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Can't connect from Nodejs to Atlas Serverless and tags: ['node-js', 'serverless']

[User]
Text:Hi dear community,I need some help. I’m trying to connect to an Atlas Serverless database from Nodejs. It just won’t work. Tried and triple checked everything I found. mongosh connect works, so user/passwd must be right, and ip whitelisting must work too. Did http://portquiz.net:27017.I followed https://www.mongodb.com/developer/how-to/atlas-serverless-quick-start/ to the letter, yet the insertOne fails with “MongoDriverError: MongoClient must be connected to perform this operation”.Help please! <3Cheers,
inki
Code:

[Assistant]
Text:Hi Inki,Thank you for pointing this out. We are working on a fix for the Node.js driver and hope to have this complete in the next couple of days. We’ll update here when the updated driver is released.For now, the python and java drivers, and mongosh should all be compatible.Thanks,
Jesse
Code:

[Assistant]
Text:Also how about php driver for connect ?
Code:

[Assistant]
Text:Hi @Sky_Team, currently the PHP driver is not yet supported. Here is a list of supported drivers: https://docs.atlas.mongodb.com/reference/serverless-instance-limitations/#minimum-driver-versions-for-serverless-instancesWe are working hard to add more support very soon!
Code:

[Assistant]
Text:Hello @Jesse_Hall,
sorry but i am quite confused. In the link that you post is wrote that NodeJS is not supported, but then I found this:MongoDB Atlas serverless instances are now available in preview! What is a serverless instance you might ask? In short, it’s an on-demand serverless database. In this article, we'll deploy a MongoDB Atlas serverless instance and perform some basic...Please can you clarify the situation? Is it supported or not NodeJS/Mongoose? If not, do you have an idea bout when it could be supported?Thanks a lot
Code:And I tried to connect with Mongoose and it give me an error:
MongoDB disconnected!
Error in MongoDb connection: MongoParseError: Text record must only set `authSource` or `replicaSet`
(node:9708) UnhandledPromiseRejectionWarning: MongoParseError: Text record must only set `authSource` or `replicaSet`
    at QueryReqWrap.callback (T:\Lavori_Software\k-core\node_modules\mongodb\lib\core\uri_parser.js:111:13)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:205:10)
(node:9708) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9708) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[Assistant]
Text:The Node.js drivers have been updated and are now working on Atlas serverless instances! Please be sure to use v4.1.0 or higher.
Code:

[Assistant]
Text:Thanks. But I still have the same problem, and I used this software with Free instance of Mongo and it work perfectly. Can you help me to find why it doesn’t work? Thanks
Code:ror in MongoDb connection: MongoParseError: Text record must only set `authSource` or `replicaSet`
(node:9708) UnhandledPromiseRejectionWarning: MongoParseError

[Assistant]
Text:Hi @KILAB_Cloud,I’m not sure which driver version mongoose is using, but you will need to be sure to use mongodb v4.1.0 or higher to work with serverless instances.
Code:

[Assistant]
Text:Thanks actualy mongoose use version 3.6.10:
default-microservice-anager@1.0.0 T:\Lavori_Software\k-core
-- mongoose@5.13.5   – mongodb@3.6.10So I have o wait until Mongoose update to version 4.1.0 (soon I hope)Thanks for the help
Code:-- mongoose@5.13.5

[Assistant]
Text:how about php driver ?
Code:

[Assistant]
Text:Hi @Sky_Team, currently the PHP driver is not yet supported. Here is a list of supported drivers: https://docs.atlas.mongodb.com/reference/serverless-instance-limitations/#minimum-driver-versions-for-serverless-instances We are working hard to add more support very soon!
Code:

[Assistant]
Text:@Jesse_Hall Hi! According to the link you posted the Node Js is supported now? In the “Connect” tab in the console, it is shown as unsupported so far. What is the status of Node Js support now?

Screenshot 2021-08-16 at 11.36.10836×122 3.89 KB

Code:

[Assistant]
Text:Hi @workreactor, Node.js v4.1.0+ is now supported. I will look into the “connect” tab documentation. Thank you for pointing that out!
Code:

[Assistant]
Text:HiI am using mongoose - v5.11.16 . And I am still getting the error
MongoParseError: Text record must only set authSource or replicaSet .Can you help hereThanks
Preveen
Code:authSourcereplicaSet

[Assistant]
Text:Hi @Knowledge_Store,What MongoDB driver are you using? v4.1.0 or greater is required.Thank you,
Jesse
Code:

[Assistant]
Text:Looks like Mongoose is using 3.6.10 MongoDB Driver.  Any plan to support 3.6.10 in Atlas Serverless in the neat future
Code:

[Assistant]
Text:Hello, next release of mongoose 6.0 now in RC1 will use Mongodb 4.1.0
we have just to wait a bit
Code:

[Assistant]
Text:Ok, thank you ! for the quick response
Code:

[Assistant]
Text:Mongoose is using 3.6.10 MongoDB Driver. Any plan to support 3.6.10 in Atlas Serverless in the neat futureI had the same issue and ended up here. I’ve tested and can confirm that mongoose 6.0.0 rc-1 works with Atlas Serverless.Thanks @Jesse_Hal for your support on this.
Code:npm i mongoose@6.0.0-rc1


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Update data across multiple collections within the same database and tags: ['node-js', 'crud', 'transactions']

[User]
Text:I’m new to MongoDB and trying to learning how to update data across multiple collections within the same database. I looked at transactions as per the blog below but the Airbnb example seems overly complicated.
https://www.mongodb.com/developer/quickstart/node-transactions/I also came across this stackoverflow post where one could use Promise, Await/Sync or $lookup.
I do not know how to apply this in my use case and if there is an easier wayTo keep it simple, I’m trying to update a field in two collections using a single query.For Example: Lets take the sample_analytics database within MongoDB as shown below. We have an accounts collection and a customers collection.My query:If I update an account number in the accounts array in the customer collection, how to update the same account number in the accounts collection. I was wondering if this is possible with a single update query.
Screen Shot 2021-08-11 at 1.32.23 pm1466×386 83.3 KB

Code:

[Assistant]
Text:Hello @Jagjit_Singh, here is the information you are looking for.I’m trying to update a field in two collections using a single query.You can update a document in two collections. And the operation can be performed atomically using MongoDB Transaction. But, the update operation on each collection will be separate - it cannot be done as a “single query”.If I update an account number in the accounts array in the customer collection, how to update the same account number in the accounts collection.You can do this with two separate update operations - one each on a collection. To make both the updates (together) atomic, use a transaction.Here is a simple example with two insert operations on two collections, inserting a document in each one - within a transaction.  This runs in mongosh.
Code:mongosh

[User]
Text:Thanks Prasad. I was able to update two collections using the script below but not sure if its the right approach, for example i wasn’t able to check if the user exists in the comments collections.The script updates the email field value in the users and comments collection in the sample_mflix database in MongoDB.How can we write the below using transactions? That will be great help.
Code:const { MongoClient } = require('mongodb');

async function main() {

    const uri = "mongodb+srv:<username>:<password>@<your-cluster-url>/sample_mflix?retryWrites=true&w=majority";

    const client = new MongoClient(uri);

    const userName = "Ned Stark"
    const newEmail = "nedstark@gmail.com"

    try {
        // Connect to the MongoDB cluster
        await client.connect();

        //user and comments collection
        users = client.db("sample_mflix").collection("users")
        comments = client.db("sample_mflix").collection("comments")

        //check if the user to be updated exists
        const filteredName = await users.find({name:userName})
        if ((await filteredName.count()) === 0) {
            console.log("No user found!");
          }

        //update email in the users collection
        userUpdate = await users.updateOne(
            { name: `${userName}`},
            { $set: { email: newEmail } },
          );
        console.log(`Updated ${userUpdate.modifiedCount} documents in users collections`);

        //update email in the comments collection
        commentUpdate = await comments.updateMany(
            { name: `${userName}`},
            { $set: { email: newEmail } },
        );

        console.log(`Updated ${commentUpdate.modifiedCount} documents in comments collections`);

        } catch (err) {
          console.error(`Something went wrong: ${err}`);
        }
        finally {
        await client.close();
        }
    }

main().catch(console.error);

[Assistant]
Text:@Jagjit_Singh,What are the results you are seeing when you run your above script?Generally, when you update a document in a collection the data (i.e, the document) gets modified based upon the query filter and the update. So, please verify those and see what is happening with your code and the data.For information about how to update documents and some examples, please study the documentation from the following two links. There is also a MongoDB University’s free video based online course to learn about programming using NodeJS Driver (see the third link below).
Code:

[User]
Text:The script works and updates the documents in the two collections. I’m hoping to achieve the same using transactions which i’m finding difficult to apply. I have reviewed the documentation links but didnt help.Even the above script I managed to get it working reading the documentation on mongodb but the transactions documentation does not have simple examples.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: MongoServerError: Document failed validation and tags: ['schema-validation']

[User]
Text:Hi,
According to Schema validation, I have a problem.
I can’t see more details about the error when working on the cluster:
I see that when i connect mongosh to the cluster and insert a document the collection, i only receive as error message :
**MongoServerError**: Document failed validationBut when i connect to local i receive additionnal informations :MongoServerError: Document failed validation
Additional information: {
failingDocumentId: ObjectId(“610b39744caa3a009907a5f0”),
details: {
operatorName: ‘$and’,
clausesNotSatisfied: [
{
index: 0,
details: {
operatorName: ‘$and’,
clausesNotSatisfied: [
{ index: 0, details: [Object] },
{ index: 3, details: [Object] },
{ index: 4, details: [Object] },
{ index: 6, details: [Object] }
]
}
}
]
}
}
Code:**MongoServerError**: Document failed validation

[Assistant]
Text:We cannot help if you do not share the schema together with the document that fails.
Code:

[User]
Text:
Code:use("school");
db.createCollection("persons",{
    validator: {
        $jsonSchema: {
            bsonType: "object",
            required: [ "first_name", "last_name", "gender" ],
            properties: {
                first_name: {
                    bsonType: "string"
                    },
                last_name: {
                    bsonType: "string"
                    },
                gender: {
                    bsonType: "string"
                    },
                category: {
                    enum: [ "student", "proffessor", "supervisor", null]
                    },
                phone: {
                    bsonType: "string"
                    },
                address: {
                    bsonType: "object",
                    properties: {
                        street_number: {
                            bsonType: "int"
                            },
                        street_name: {
                            bsonType: "string"
                            },
                        house_number: {
                            bsonType: "int"
                            },
                        }
                }
            }
        }
    },
});

use("school");
    db.persons.insertOne({
        first_name: "August",
        last_name: "Marline",
        gender: 2,
        category: "proffessor",
        phone: "581",
        address: {
            street_number: 345,
            street_name: "Auclair",
            house_number: 67
        }
    });

[Assistant]
Text:So easy, I do not know how you could not set it yourself.andgender: 2,And to be clear 2 is a number, not a string.
Code:gender: {
                    bsonType: "string"
                    },
gender: 2,

[User]
Text:Hi @steevej ,Thank you, I know. Thanks for reply.As i told in my first post, i’m connected in a cluster on atlass.For the insertOne query, i puted 2 in the gender in order to see if the validator will show a error message according to the information that i inserted.  So, it’s okey, I had this error message :
MongoServerError: Document failed validation
But, mongosh does not retrun additional information in order to see where at what fileld is the error.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Single fetch with skip and limit returns unexpected result and tags: ['queries']

[User]
Text:I have MongoDB collection that have 5 documents, which I am running a query against it. The query fetches one document at a time.the first 2 fetches return the expected result, while the last 3 fetches are fetching the third document only, while the last  and second last documents are not being fetched at all.Notice the last three documents have the same id.db.A.find({}).limit(1).skip(0).sort({“startDate”: 1});
{ “_id” : ObjectId(“61097e72e0903145c925e445”)db.A.find({}).limit(1).skip(1).sort({“startDate”: 1});
{ “_id” : ObjectId(“61098839ddd36878ba1acfef”)db.A.find({}).limit(1).skip(2).sort({“startDate”: 1});
{ “_id” : ObjectId(“6112f90c5d7fc9e3ad1385ee”)db.A.find({}).limit(1).skip(3).sort({“startDate”: 1});
{ “_id” : ObjectId(“6112f90c5d7fc9e3ad1385ee”)db.A.find({}).limit(1).skip(4).sort({“startDate”: 1});
{ “_id” : ObjectId(“6112f90c5d7fc9e3ad1385ee”)
Code:

[Assistant]
Text:Could we have the full documents?We are missing some information because there is no projection that only keep _id but we do not see the value of the field you sort on.With full document is proper JSON format we could import in our env. and experiment.
Code:

[User]
Text:Below is the entire collection{ “_id” : ObjectId(“61097e72e0903145c925e445”), “startDate” : ISODate(“2021-06-14T15:47:19.551Z”), “endDate” : ISODate(“2021-09-14T15:47:19.551Z”),  “lastModifiedDate” : ISODate(“2021-08-03T17:35:48.800Z”), “_class” : “entity.Offer” }
{ “_id” : ObjectId(“61098839ddd36878ba1acfef”), “startDate” : ISODate(“2021-06-14T15:47:19.551Z”), “endDate” : ISODate(“2021-09-14T15:47:19.551Z”),  “lastModifiedDate” : ISODate(“2021-08-03T17:35:48.800Z”), “_class” : “entity.Offer” }
{ “_id” : ObjectId(“6112f90c5d7fc9e3ad1385ee”), “startDate” : ISODate(“2021-06-14T15:47:19.551Z”), “endDate” : ISODate(“2021-09-14T15:47:19.551Z”),  “lastModifiedDate” : ISODate(“2021-08-03T17:35:48.800Z”), “_class” : “entity.Offer” }
{ “_id” : ObjectId(“611415503d6e6707ce6667c0”), “startDate” : ISODate(“2021-06-14T15:47:19.551Z”), “endDate” : ISODate(“2021-09-14T15:47:19.551Z”),  “lastModifiedDate” : ISODate(“2021-08-03T17:35:48.800Z”), “_class” : “entity.Offer” }
{ “_id” : ObjectId(“61150b9c04457a8f8bcd44ab”), “startDate” : ISODate(“2021-06-14T15:47:19.551Z”), “endDate” : ISODate(“2021-09-14T15:47:19.551Z”),  “lastModifiedDate” : ISODate(“2021-08-03T17:35:48.800Z”), “_class” : “entity.Offer” }
Code:

[Assistant]
Text:The quotes are messed up by HTML.Please enclose withing 2 lines of triple back ticks such as
Code:

[User]
Text:sorry for the hassle
Code:[
    {
        "id": "61097e72e0903145c925e445",
        "startDate": "2021-06-14T15:47:19.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "61098839ddd36878ba1acfef",
        "startDate": "2021-06-14T15:47:19.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "6112f90c5d7fc9e3ad1385ee",
        "startDate": "2021-06-14T15:47:19.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "611415503d6e6707ce6667c0",
        "startDate": "2021-06-14T15:47:19.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "61150b9c04457a8f8bcd44ab",
        "startDate": "2021-06-14T15:47:19.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    }
]

[User]
Text:looking at the start date, you will see it is identical.I just changed the startDate now to be one second difference between each document. I can see now the queries are returning the expected result.so below is my new JOSN
Code:[
    {
        "id": "61097e72e0903145c925e445",
        "startDate": "2021-06-14T15:47:19.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "61098839ddd36878ba1acfef",
        "startDate": "2021-06-14T15:47:20.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "6112f90c5d7fc9e3ad1385ee",
        "startDate": "2021-06-14T15:47:21.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "611415503d6e6707ce6667c0",
        "startDate": "2021-06-14T15:47:22.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    },
    {
        "id": "61150b9c04457a8f8bcd44ab",
        "startDate": "2021-06-14T15:47:23.551Z",
        "endDate": "2021-09-14T15:47:19.551Z"
    }
]

[Assistant]
Text:I have tested mongo, mongosh, Compass, Atlas.This is not the expected result.I only get the correct result in Compass Aggregation.To me it looks like a serious issue.  As a temporary fix, you may sort { startDate:1 , _id:1 } and that seems to work.I have flagged the thread so someone better suited will take a look at it.
Code:

[Assistant]
Text:Hi @Energy_N_A, @steevej,The issue is that is sorting by identical values does not produce a deterministic sort order:I just changed the startDate now to be one second difference between each document. I can see now the queries are returning the expected result.Per Using skip() with sort() in the documentation:If using  skip()  with  sort() , be sure to include at least one field in your sort that contains unique values, before passing results to  skip() .Sorting on fields that contain duplicate values may return an inconsistent sort order for those duplicate fields over multiple executions, especially when the collection is actively receiving writes.The easiest way to guarantee sort consistency is to include the _id field in your sort query.Regards,
Stennie
Code:skip()sort()skip()sort()skip()_id

[Assistant]
Text:Thanks.I did not look at the documentations in such a detailed way.  So it is a well know issue, shame on me.The intuition of adding _id:1 to the sort order was the good one. Yeah!
Code:

[User]
Text:Thanks a lot Steve!Appreciate your help!
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How to use regex in the lookup pipeline? and tags: ['aggregation', 'queries', 'dot-net']

[User]
Text:Consider this aggregate query as a sample, and I want to fetch the results based on the code which contains the first 5 digits of the ProductSerial. So I’m using the starts with regex option to pull the data. How to frame the regex string from previous stage values.Aggregate:
Code:  db.getCollection("ProductInfo").find(
    {
        "ProductSerial" : /^38990.*/i
    }
  $Project:
  {
    ProductCode : '$ProductCode'
  }

  $lookup: {
        from: 'ForeignCollection',
        let: {
            variable: '$ProductCode'
        },
        pipeline: [
		    {
			   {
                $match: {
                    ProductSerial: {
                        $regex: "^$$variable.*",
                        $options: "i"
                    }
                }
            }
        ],
        as: "Product"
    }

[Assistant]
Text:Hi @Sudhesh_Gnanasekaran ,I think you should build the $let stage with $concat expression :And use $expr in your match :Perhaps it might work even without concat as variable in a match only work with exprThanks
Pavel
Code:let: {
            variable: {$concat :["^",'$ProductCode',".*"]}
        }
{
                $match: {
                  $expr : {  ProductSerial: {
                        $regex: "$$variable",
                        $options: "i"
                    }
                }}
            }

[Assistant]
Text:You cannot mix aggregation and match (find) expressions, @Pavel_Duchovny - if you are inside $expr then you can only use aggregation syntax, and Field:{$regex: ...  is a match expression.
Code:$exprField:{$regex: ...

[Assistant]
Text:If you are on 4.2 or later, you can adjust the suggestion from @Pavel_Duchovny and use this aggregation regex expression.So if you have a previous stage which figures out the “starts with” substring, you can use that inside $expr after assigning it to a variable like you are doing.The stage would be:
Code:$expr{$lookup: {
    from: 'ForeignCollection',
    let: { regex: {$concat:["^", '$ProductCode']}},
    pipeline: [
         { $match: {$expr: {
               $regexMatch:{
                   input: "$ProductSerial",
                   regex: "$$regex",
                   options: "i"
               }
        }}}
    ],
    as: "Product"
}}


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Unable to launch MongoDB in Windows 10 and tags: ['configuration']

[User]
Text:I am working mongodb 4.4 o Windows 10, and it was working fine. I didnt even need to launch it explicitly as it runs as service and could connect to it using mongo compass. But now I see that on computer start it doesnt start, and so when I try to run mongod command explicitly, I get message:Even though mongof.cfg has this:I am not able to understand the issue.
Code:C:\Program Files\MongoDB\Server\4.4\bin>mongod
{"t":{"$date":"2020-09-17T02:33:16.379-07:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-09-17T02:33:16.383-07:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-17T02:33:16.383-07:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-17T02:33:16.384-07:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":13320,"port":27017,"dbPath":"C:/data/db/","architecture":"64-bit","host":"3INDGHILDIYA1"}}
{"t":{"$date":"2020-09-17T02:33:16.384-07:00"},"s":"I",  "c":"CONTROL",  "id":23398,   "ctx":"initandlisten","msg":"Target operating system minimum version","attr":{"targetMinOS":"Windows 7/Windows Server 2008 R2"}}
{"t":{"$date":"2020-09-17T02:33:16.384-07:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1-rc2","gitVersion":"95ea09d61932f51a37a63a10f4d0e0c1fced4723","modules":[],"allocator":"tcmalloc","environment":{"distmod":"windows","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-17T02:33:16.384-07:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Microsoft Windows 10","version":"10.0 (build 17134)"}}}
{"t":{"$date":"2020-09-17T02:33:16.384-07:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-09-17T02:33:16.385-07:00"},"s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory C:\\data\\db\\ not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
{"t":{"$date":"2020-09-17T02:33:16.385-07:00"},"s":"I",  "c":"REPL",     "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":10000}}
{"t":{"$date":"2020-09-17T02:33:16.386-07:00"},"s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"}
{"t":{"$date":"2020-09-17T02:33:16.386-07:00"},"s":"I",  "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"}
{"t":{"$date":"2020-09-17T02:33:16.387-07:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2020-09-17T02:33:16.388-07:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"}
{"t":{"$date":"2020-09-17T02:33:16.389-07:00"},"s":"I",  "c":"STORAGE",  "id":4784906, "ctx":"initandlisten","msg":"Shutting down the FlowControlTicketholder"}
{"t":{"$date":"2020-09-17T02:33:16.401-07:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2020-09-17T02:33:16.412-07:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"}
{"t":{"$date":"2020-09-17T02:33:16.413-07:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"}
{"t":{"$date":"2020-09-17T02:33:16.424-07:00"},"s":"I",  "c":"CONTROL",  "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"}
{"t":{"$date":"2020-09-17T02:33:16.428-07:00"},"s":"I",  "c":"FTDC",     "id":4784926, "ctx":"initandlisten","msg":"Shutting down full-time data capture"}
{"t":{"$date":"2020-09-17T02:33:16.429-07:00"},"s":"I",  "c":"STORAGE",  "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"}
{"t":{"$date":"2020-09-17T02:33:16.437-07:00"},"s":"I",  "c":"STORAGE",  "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2020-09-17T02:33:16.442-07:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2020-09-17T02:33:16.449-07:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2020-09-17T02:33:16.450-07:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}
# Where and how to store data.
storage:
  dbPath: C:\Program Files\MongoDB\Server\4.4\data

[Assistant]
Text:When you start manually mongod without any options it will try to bring up mongod on default port 27017 and default directory /data/db
Since the dir does not exist it is failingComing back to your Windows mongod which runs as service please check why it is not up after reboot
It should come up automatically
Check your taskmanager services.Should see mongod service
Check if it is configured to auto start or not
Code:

[Assistant]
Text:As @Ramachandra_Tummala mentioned, you should first understand why it’s not starting with your computer like it used to.If you still want to start mongod manually after that, you need to provide the configuration like so:Read mongod --help or the documentation for more details.
Code:mongodmongod --config <PATH_TO_CONFIG>
mongod --help

[User]
Text:So how to configure mongod to autostart?
Code:

[Assistant]
Text:
Code: