[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 take backup of MongoDB users and roles without data? and tags: ['database-tools', 'backup']

[User]
Text:Anyone knows how to take backup of mongodb users and roles without data ?
Code:

[Assistant]
Text:Hey @Ajithkumar_SThe roles are stored on system.roles in the admin db and users are the system.users collection. Therefore you can take backups of just those collections if you want.
Code:system.rolessystem.users

[User]
Text:Hi Natac, I have already tried this.I can able to take backup.But while importing to admin database its shows some error.
Code:

[User]
Text:Pasted the error below,[root@ajith
/]# /mongo_ak/mongodb4_0/bin/mongorestore --port=27018 --db admin --dir=/dump/admin/system.users.bson
2020-03-02T12:31:46.664+0000	checking for collection data in /dump/admin/system.users.bson
2020-03-02T12:31:46.664+0000	assuming users in the dump directory are from <= 2.4 (auth version 1)
2020-03-02T12:31:46.665+0000	Failed: the users and roles collections in the dump have an incompatible auth version with target server: cannot restore users of auth version 1 to a server of auth version 5
2020-03-02T12:31:46.665+0000	0 document(s) restored successfully. 0 document(s) failed to restore.
[root@casdendra02 /]#
Code:

[Assistant]
Text:Are the versions of Mongod the same?
This error maybe outside the level of my knowledge… sorry.
Code:

[User]
Text:Yes @Natac13. Both the MongoDB versions are same.We don’t have any direct method to dump users and roles with out data.But I have find a alternative method. To do this.
Code:

[User]
Text:Sorry for the typo,Yes @Natac13. Both the MongoDB versions are same.We don’t have any direct method to (dump and restore) users and roles with out data.But I have find a alternative method. To do this.
Code:

[Assistant]
Text:The admin is a special collection, I don’t think you can just dump/restore like that (more knowledgeable poster required)That said mongorestore has a flag for restoring db users and roles.Are you making a seed database?  Once the users are created drop collections and then dump that whole mongodb.  Then restore that with the previously mentioned flag.
Code:

[Assistant]
Text:Pasted the error below,[root@ajith
/]# /mongo_ak/mongodb4_0/bin/mongorestore --port=27018 --db admin --dir=/dump/admin/system.users.bson
2020-03-02T12:31:46.664+0000 checking for collection data in /dump/admin/system.users.bson
2020-03-02T12:31:46.664+0000 assuming users in the dump directory are from <= 2.4 (auth version 1)
2020-03-02T12:31:46.665+0000 Failed: the users and roles collections in the dump have an incompatible auth version with target server: cannot restore users of auth version 1 to a server of auth version 5
2020-03-02T12:31:46.665+0000 0 document(s) restored successfully. 0 document(s) failed to restore.
[root@casdendra02 /]#Was the source database upgraded at some point from a MongoDB version lower then 2.6 on it’s way to MongoDB 4.0?   Is it possible that the authSchemaUpgrade was never performed on the source during an upgrade?
Code:

[User]
Text:HI @Michael_Grayson,Here, I didn’t upgrade anything.I have just installed the 4.0 binary package and tried the test case.
Code:

[User]
Text:Dear @chris,I know the collections inside the admin database are special collections.But my requirement is, I need to backup the users and roles for the particular database without data and the database size is 3.4 TB.I have tried all the methods available in mongodb but nothing is help for me.After that I made some changes in the dump file after that its works.My question is, any possible ways that anyone know to dump the users and roles directly from MongoDB ?
Code:

[User]
Text:without the data. Is so important.
Code:

[Assistant]
Text:This might be really naive but can’t you achieve what you want with https://docs.mongodb.com/manual/reference/method/db.getUsers/?
Code:

[User]
Text:HI @steevej,
Using db.getUsers(), we can get all the users list, yes we can take this user backup but how will restore.
Code:

[Assistant]
Text:You probably can write a simple .js loop over all documents that calls https://docs.mongodb.com/manual/reference/method/db.createUser/.Note that you do not get any password with db.getUsers() so you will have to generate new password.
Code:

[User]
Text:Yes @steevej,You are correct, that won’t help for backup and restore. It will help to take the users list only.But I have some other methods to backup and restore users separately.
Code:

[User]
Text:If you wanted I will explain the steps.
Code:

[User]
Text:Otherwise we don’t have any option to take backup & restore, users and roles database wise(without data).
Code:

[Assistant]
Text:I do not need that.  And I do not follow anymore.In one postI need to backup the users and roles for the particular database without dataand nowBut I have some other methods to backup and restore users separately
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: "Server selection timed out after 30000 ms" error during mongodb compass connection and tags: []

[User]
Text:Hi ,everyone ,I have followed all the steps but unable to connect and it is showing this error.
Code:

[Assistant]
Text:Hi @ROHIT_KUMAR_48314,Are you connected to any Corporate network / VPN connection ?Can you please make sure you are able to ping and telnet the cluster ?ping cluster0-shard-00-00-jxeqq.mongodb.nettelnet cluster0-shard-00-00-jxeqq.mongodb.net 27017In addition to this, Please confirm that port 27017 is not blocked by clicking http://portquiz.net:27017.If any of this is an issue then I would suggest you to contact your IT department to see if there is a workaround or try to make the request from another location such as your home network.Hope it helps!Thanks,
Shubham Ranjan
Curriculum Support Engineer
Code:

[Assistant]
Text:Hello. I having this problem too. But yesterday was working just fine. I checked the ping, telnet and the port availability and all is working great, but still receive “Server selection timed out after 30000 ms” in Compass.
Code:

[Assistant]
Text:Are you able to connect with shell?
Try to restart compass and see
If you are using favorites try to create a new one and check if it works
Code:

[Assistant]
Text:Didn’t tried with shell, but looking in this answer Unable to connect to MongoDB compass (barryoneill answer) I found the solution was checking SRV option (I swear I connect just fine without checking it yesterday).
Code:

[Assistant]
Text:Hi @Yamil_67132,This must be a temporary network issue. Please try to connect after some time and hopefully it should be fine.Thanks,
Shubham Ranjan
Curriculum Support Engineer
Code:

[Assistant]
Text:Is this still an issue?  I just registered and I am trying to connect and get the same timeout issue.
Code:

[Assistant]
Text:I solved the problem by downloading the “Community” edition rather than the version linked in the course.  All seems well now.
Code:

[Assistant]
Text:Hi @cpwolf3,The Community version of Compass does not have Schema Tab, which you need to have in Compass in order to do the labs.It might be a network/firewall related issue. Please try to connect from some other location such as your home network.If the issue still persists then please feel free to get back to us.Thanks,
Shubham Ranjan
Curriculum Support Engineer
Code:

[Assistant]
Text:You should install mongodb compass from the link in the course. You might have installed community server.
Code:

[Assistant]
Text:C:\Users\Deevi>ping cluster0-shard-00-00-jxeqq.mongodb.netPinging ec2-34-195-121-130.compute-1.amazonaws.com [34.195.121.130] with 32 bytes of data:
Reply from 34.195.121.130: bytes=32 time=258ms TTL=48
Reply from 34.195.121.130: bytes=32 time=257ms TTL=48
Reply from 34.195.121.130: bytes=32 time=258ms TTL=48
Reply from 34.195.121.130: bytes=32 time=257ms TTL=48Ping statistics for 34.195.121.130:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 257ms, Maximum = 258ms, Average = 257msThis server listens on all TCP ports, allowing you to test any outbound TCP port.You have reached this page on port  27017 .Your network allows you to use this port. (Assuming that your network is not doing advanced traffic filtering.)Network service: unknown
but still im getting the same error
Code:

[Assistant]
Text:Hi @vivek_25217,Even though these basic tests passes, network is still a problem. Have you tried connecting from some other network such as your home network/ mobile hotspot ?If nothing works then you can import the data locally on your machine and complete the labs. The instructions are mentioned in this post.Hope it helps!Thanks,
Shubham Ranjan
Curriculum Services Engineer
Code:

[Assistant]
Text:@Shubham_Ranjan
I think atlas cluster which course is trying to give access, have not set NETWORK ACCESS settings in atlas dashboard, IP WHITELIST as “ALLOW ACCESS FROM ANYWHERE”
Code:

[Assistant]
Text:Hi @Sahil_66399,Are you talking about the class atlas cluster ?If yes, then I can confirm that this cluster is publicly available. If in case you are having any problem then please share a screenshot of the error message that you are getting.Thanks,
Shubham Ranjan
Curriculum Services Engineer
Code:

[Assistant]
Text:class atlas clusterYes I was mistaken while filing details appropriately.
Its working now fine.
I am really amazed seeing such nice course and active discussion forum which shows everyone is taking interest learning mongoDB and practicing hands on labs.I am really thankful to Team mongoDB for giving us such remarkable platform and access to live cluster, labs, everything to learn about mongoDB.
Code:

[Assistant]
Text:Hi @Sahil_66399,I’m so glad that you found the course helpful .And also let me take this opportunity to thank some of our Super Users who are constantly helping our learners in the discussion forum @007_jb, @Ramachandra_37567 and @steevej-1495    .Thanks,
Shubham Ranjan
Curriculum Services Engineer
Code:

[Assistant]
Text:I was getting this error when attempting to connect to my sandbox using Compass. I was able to connect successfully to my sandbox using the shell. I loaded the data for the movies and was in the part of the course where you are supposed to connect to your sandbox using Compass. I tried following the instructions in the video, but some things have changed, and who knows, maybe I made a typo.What fixed it for me was copying and pasting the connection string for Mongo Compass on Atlas for my sandbox cluster, and then changing ONLY the username and password, without clicking around on anything else.
2020-02-202736×1824 533 KB

Code:

[Assistant]
Text:Hi @William_Moore_97877,Thanks for sharing. I believe there must have been a typo in the connection string which was causing this issue.Thanks,
Shubham Ranjan
Curriculum Services Engineer
Code:

[Assistant]
Text:VPN connectionHi @Shubham_Ranjan,i cannot ping the cluster but able to confirm that port 27017 is not blocked.  i’m trying to connect at work - what should i ask my administrator to do for me?thank you!
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: Reverse $unwind into $lookup array and tags: ['aggregation']

[User]
Text:Hello everyone, I’ve 3 collections and i want to show all of them and for that i use lookup.And after that i want to use divide  method on one of the collection to divide some fields by some value(i.e. 5) but it returns an error that $divide can’t be used on array, so i used unwind and apply the divide method and it was working perfectly but the issue is that i want to merge them back in one array. Followed are the collections and query and required output.----------------------- Query --------------------------- Expected Output ----------
Code:---------- c_accounts --------------
//   01
{
    "accountId" : "12345",
    "customerId" : "1234",
    "accountNumber" : "AC12345",
    "balance" : 3242.2,
    "balanceAed" : 32423.23
},
//   02
{
    "accountId" : "12346",
    "customerId" : "1234",
    "accountNumber" : "AC12346",
    "balance" : 12131,
    "balanceAed" : 123.1
}
---------c_transactions----------
//   01
{
     "customerId" : "1234",
     "accountId" : "12345",
     "transactionId" : "T12345",
     "referenceNumber" : "R12345"
},
//   02
{
     "customerId" : "1234",
     "accountId" : "12346",
     "transactionId" : "T12346",
     "referenceNumber" : "R12346"
}
-------------c_cards---------------
//    01
{
        "customerId" : "1234",
        "accountId" : "12345",
        "cardId" : "C1234",
        "cardHolderName" : "John Doe",
        "LimitAmount" : 15000.5,
        "PaymentAmount" : 5000.5

},
//   02
{
        "customerId" : "1234",
        "accountId" : "12346",
        "cardId" : "C1236",
        "cardHolderName" : "John Doe",
        "LimitAmount" : 15000.5,
        "PaymentAmount" : 5000.5

}
    db.getCollection("accounts").aggregate(
    [
        {
            "$match" : {
                "customerId" : "1234"
            }
        },
        {
            "$lookup" : {
                "from" : "transactions",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Transactions"
            }
        },
        {
            "$lookup" : {
                "from" : "cards",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Cards"
            }
        },
        {
            "$unwind" : {
                "path" : "$Cards"
            }
        },
        {
            "$project" : {
                "_id" : 0.0,
                "Transactions._id" : 0.0,
                "Cards._id" : 0.0
            }
        },
        {
            "$project" : {
    					// C-Accounts
    							"accountId" : 1.0,
    							"customerId" : 1.0,
    							"accountNumber" : 1.0,
    							"balance" : 1.0,
    							"balanceAed" : 1.0,
    					// C-Transactions
    							"Transactions.accountId" : 1.0,
    							"Transactions.customerId" : 1.0,
    							"Transactions.transactionId" : 1.0,
    							"Transactions.referenceNumber" : 1.0,
    					// C-Cards
    							"Cards.customerId" : 1.0,
    							"Cards.accountId" : 1.0,
    							"Cards.cardId" : 1.0,
    							"Cards.cardHolderName" : 1.0,

    							"Cards.LimitAmount" : {
    								"$divide" : [
    									"$Cards.LimitAmount",
    									5.0
    								]
    							},
    							"Cards.PaymentAmount" : {
    								"$divide" : [
    									"$Cards.PaymentAmount",
    									5.0
    								]
    							}
    					}
        }
    ],
    {
        "allowDiskUse" : false
    }
    );
[
   {
    "accountId" : "12345",
    "customerId" : "1234",
    "accountNumber" : "AC12345",
    "balance" : 3242.2,
    "balanceAed" : 32423.23
   },{
    "accountId" : "12346",
    "customerId" : "1234",
    "accountNumber" : "AC12346",
    "balance" : 12131,
    "balanceAed" : 123.1
 },
Transactions:[
   {
     "customerId" : "1234",
     "accountId" : "12345",
     "transactionId" : "T12345",
     "referenceNumber" : "R12345"
},
{
     "customerId" : "1234",
     "accountId" : "12346",
     "transactionId" : "T12346",
     "referenceNumber" : "R12346"
   }
],
Cards: [{
        "customerId" : "1234",
        "accountId" : "12345",
        "cardId" : "C1234",
        "cardHolderName" : "John Doe",
        "LimitAmount" : 5000.5,
        "PaymentAmount" : 1000.5

},
  {
        "customerId" : "1234",
        "accountId" : "12346",
        "cardId" : "C1236",
        "cardHolderName" : "John Doe",
        "LimitAmount" : 3000.5,
        "PaymentAmount" : 1000.5
  }
]
]

[Assistant]
Text:I am not to sure if I understand your requirements but I would take a look at the $push in https://docs.mongodb.com/manual/reference/operator/update/push/#up._S_push
Code:

[Assistant]
Text:Have you considered using the $map operator in the $project stage instead of $unwind?$map will apply an operation to each element in the array:Using $map will remove the need to $unwind with a subsequent $group.
Code:$map$project$unwind$map$map$unwind$group

[User]
Text:$push with $group, but the issue is with the main collection. here is the group clause:
{
_id: “customerId”,
“Accounts” : {$push: “$accounts”},
“Transactions” : {$push: “$Transactions”},
“Cards” : {$push: “$Cards”}
}
Code:

[Assistant]
Text:Don’t use $unwind or $group  - just use $divide inside of $map, like Justin suggested.
Code:$unwind$group

[User]
Text:Then it show null value in the field.
Code:

[Assistant]
Text:Hi @Nabeel_Raza,Thanks for providing the example input, the expected output and the aggregation pipeline that you’ve tried.i used unwind and apply the divide method and it was working perfectly but the issue is that i want to merge them back in one array.As mentioned by Justin and Asya, you can utilise $map instead of $unwind here. So replacing all of the pipeline stages after $unwind from your example,  below is an example on how you could utilise $divide inside of $map :This should have solved your issue with using $unwind and having to merge them back in. See also $addFields for more information.However looking at your desired output, it looks like there is another issue. It seems that you’re trying to group all documents in accounts, transactions and cards collections matching customerId to a single document. If this is the case, then you need to group before the $lookup, for example:Having said all the above, after looking at the collection schemas and the desired output of your aggregation pipeline, if this is a frequently used query I’d recommend to reconsider the collection schemas. Please review Schema Design: Summary for examples of different patterns.Regards,
Wan.
Code:$map$unwind$unwind$divide$mapdb.accounts.aggregate([
        {"$match" : { "customerId" : "1234" } },
        {
            "$lookup" : {
                "from" : "transactions",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Transactions"
            }
        },
        {
            "$lookup" : {
                "from" : "cards",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Cards"
            }
        },
        {"$addFields": {
                "Cards": {
                    "$map":{
                        "input":"$Cards",
                        "in": {
                         "customerId": "$$this.customerId",
                         "accountId": "$$this.accountId",
                         "cardId": "$$this.cardId",
                         "cardHolderName": "$$this.cardHolderName",
                         "LimitAmount": { "$divide": [ "$$this.LimitAmount", 5.0 ] },
                         "PaymentAmount": { "$divide": [ "$$this.PaymentAmount", 5.0 ] },
                        }
                    }
                },
            }
        },
        {"$project": {
            "_id":0,
            "Transactions._id":0
            }
        }
])
$unwindaccountstransactionscardscustomerId$lookupdb.accounts.aggregate([
        {"$match" : { "customerId" : "1234"} },
        {
            "$group": {
                "_id": null,
                "Accounts":{"$push":"$$ROOT"}
            }
        },
        {
            "$lookup" : {
                "from" : "transactions",
                "localField" : "Accounts.accountId",
                "foreignField" : "accountId",
                "as" : "Transactions"
            }
        },
        {
            "$lookup" : {
                "from" : "cards",
                "localField" : "Accounts.accountId",
                "foreignField" : "accountId",
                "as" : "Cards"
            }
        },
        {"$addFields": {
                "Cards": {
                    "$map":{
                        "input":"$Cards",
                        "in": {
                        "customerId": "$$this.customerId",
                        "accountId": "$$this.accountId",
                        "cardId": "$$this.cardId",
                        "cardHolderName": "$$this.cardHolderName",
                        "LimitAmount": { "$divide": [ "$$this.LimitAmount", 5.0 ] },
                        "PaymentAmount": { "$divide": [ "$$this.PaymentAmount", 5.0 ] },
                        }
                    }
                },
            }
        },
        {"$project" : {
            "_id" : 0,
            "Accounts._id": 0,
            "Transactions._id" : 0,
            "Cards._id" : 0
            }
        }
    ])

[User]
Text:@wan it through null values. how can we avoid that.
Code:{
            "customerId" : "1234",
            "accountId" : "12345",
            "cardId" : "C1238",
            "cardHolderName" : "John Moe",
            "LimitAmount" : null,
            "PaymentAmount" : null
        }

[User]
Text:Here is the solution of the above problem.
Code:db.getCollection("accounts").aggregate(
    [
        {
            "$match" : {
                "customerId" : "1234"
            }
        },
        {
            "$lookup" : {
                "from" : "transactions",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Transactions"
            }
        },
        {
            "$lookup" : {
                "from" : "cards",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Cards"
            }
        }
        ,
        {
            "$unwind" : {
                "path" : "$Cards"
            }
        },
        {
            "$project" : {
                "accountId" : 1.0,
                "customerId" : 1.0,
                "accountNumber" : 1.0,
                "balance" : 1.0,
                "balanceAed" : 1.0,

                "Transactions.accountId" : 1.0,
                "Transactions.customerId" : 1.0,
                "Transactions.transactionId" : 1.0,
                "Transactions.referenceNumber" : 1.0,

                "Cards.customerId" : 1.0,
                "Cards.accountId" : 1.0,
                "Cards.cardId" : 1.0,
                "Cards.cardHolderName" : 1.0,
                "Cards.LimitAmount" : {
                    "$divide" : [
                        "$Cards.LimitAmount",
                        5.0
                    ]
                },
                "Cards.PaymentAmount" : {
                    "$divide" : [
                        "$Cards.PaymentAmount",
                        5.0
                    ]
                },
            }
        },
        {
       $group:
         {
           _id: {
                "accountId" : "$accountId",
                "customerId" : "$customerId",
                "accountNumber" : "$accountNumber",
                "balance" : "$balance",
                "balanceAed" : "$balanceAed",
            },
           Transactions: { $addToSet: "$Transactions" }
           ,Cards: { $addToSet: "$Cards" }
         }
        },
        {
            "$project" : {
                "_id" : 0,
                "Accounts":"$_id",
                "Transactions" : "$Transactions",
                "Cards" : "$Cards"
            }
        }
     ],
    {
        "allowDiskUse" : true
    }
);

[Assistant]
Text:@Nabeel_Raza, glad that you’ve found a solution.I noticed that the output of the aggregation pipeline is different to the expected output from the original post. Given your collection/document examples from the original post, an example pipeline to get similar output to the pipeline above is below:This should avoid using $unwind and grouping by Accounts collection. Also, avoiding a result of an array of arrays for Transactions field.Worth mentioning that if you’re dealing with monetary data i.e. LimitAmount and PaymentAmount and you need to emulate decimal rounding with exact precision I would recommend to look into Decimal BSON type. See also Model Monetary Data for more information.Still related to data modelling, I would suggest to review Schema Design: Summary for example of different patterns.Regards,
Wan.
Code:db.accounts.aggregate( [
        { "$match" : {  "customerId" : "1234"} },
        {
            "$lookup" : {
                "from" : "transactions",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Transactions"
            }
        },
        {
            "$lookup" : {
                "from" : "cards",
                "localField" : "accountId",
                "foreignField" : "accountId",
                "as" : "Cards"
            }
        },
        {"$addFields": {
                "Accounts.accountId": "$accountId",
                "Accounts.customerId": "$customerId",
                "Accounts.accountNumber": "$accountNumber",
                "Accounts.balance":"$balance",
                "Accounts.balanceAed":"$balanceAed",
                "Cards": {
                    "$map":{
                        "input":"$Cards",
                        "in": {
                         "customerId": "$$this.customerId",
                         "accountId": "$$this.accountId",
                         "cardId": "$$this.cardId",
                         "cardHolderName": "$$this.cardHolderName",
                         "LimitAmount": { "$divide": [ "$$this.LimitAmount", 5.0 ] },
                         "PaymentAmount": { "$divide": [ "$$this.PaymentAmount", 5.0 ] },
                        }
                    }
                },
            }
        },
        {
            "$project" : {
                "_id" : 0,
                "Transactions._id" : 0,
                "Cards._id" : 0,
                "accountId":0,
                "customerId":0,
                "accountNumber":0,
                "balance":0,
                "balanceAed":0
            }
        },
])
$unwindAccountsTransactionsLimitAmountPaymentAmount


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

[System] The following conversation has title: Failed to set up listener: SocketException: Cannot assign requested address when using hostname and tags: ['configuration']

[User]
Text:Hi, I’m trying to setup a replication cluster, but on my oracle cloud vm I can’t set the hostname without giving an error.I used nslookup to make sure if the A record was correct in the vm’s dns server and it was, on another vps I have somewhere else it works fine.
This is the config file template I’m using for all my servers and the error log: https://gist.github.com/GameMaster2030/b714d164577d4f1808aa3cfa0e53ef1dXX is a number, so 01, 02 etc.

1041×155 8.89 KB
Here is my DNS config.
Any idea why it is giving this error and how I can fix it?
Code:

[Assistant]
Text:@GameMaster2030The message “Cannot assign requested address” suggests that the hostname/IP you are trying to bind does not resolve to a local network interface.A few things to check:Are the full hostnames (eg 01.mongodb.DOMAIN.nl) resolvable on all of your replica set members?  For a quick test, try ping or nslookup using the expected hostname. Your screenshot of DNS details suggests that the replica set members would need to include DOMAIN.nl in their DNS search domain in order to resolve the full hostname.Does the hostname resolve to an IP address that is also local to the machine (eg on Linux the IP should be listed in the output of ifconfig -a  | grep "inet").If the name resolution appears to check out, can you confirm what O/S version is running in your VMs?Regards,
Stennie
Code:01.mongodb.DOMAIN.nlpingnslookupDOMAIN.nlifconfig -a  | grep "inet"

[User]
Text:All the hostnames are resolvable on all the hosts:
Host 1:

Host 2:

Host 3:
The ip isn’t listed on host 2 and 3, as seen on the screenshots. Host 1 does have the ip listed and is the only host that works. Maybe that is the issue, how can I add the IP?All of them are running Ubuntu 18.04
Code:

[Assistant]
Text:The ip isn’t listed on host 2 and 3, as seen on the screenshots. Host 1 does have the ip listed and is the only host that works. Maybe that is the issue, how can I add the IP?It sounds like DNS resolution is fine on all your VMs, but two of them are missing the expected local IPs.If an IP isn’t associated with a local network interface, the original error message that you encountered would be expected. The MongoDB process cannot bind (aka “listen to”) an IP address that isn’t local.The fix for this would be outside of MongoDB: your VMs need to have the extra network interfaces assigned & configured.However, I also note that the IPs you are trying to add are public IPs (the existing 10.* IPs are private IPv4 addresses). Typically you would only want to bind to private IPs and have access to the database servers secured via VPN or SSH tunnel from trusted application servers. For more information on security measures please see the MongoDB Security Checklist.Regards,
Stennie
Code:10.*

[User]
Text:So I got it to work and it’s up now, but now when I try to connect to hosts 2 and 3 externally, it gives the following error:But when I connect to the hostname on the host itself it works fine.
Code:E QUERY    [js] Error: couldn't connect to server 02.mongodb.DOMAIN.nl:27017, connection attempt failed: NetworkTimeout: Error connecting to 02.mongodb.DOMAIN.nl:27017 (X.X.X.X:27017) :: caused by :: Socket operation timed out :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed

[Assistant]
Text:Error connecting to 02.mongodb.DOMAIN.nl:27017 (X.X.X.X:27017) :: caused by :: Socket operation timed outI assume the expected IP is logged here, so the issue is probably related to firewall rather than DNS.Drivers/clients connecting to a replica set will use the hostnames listed in the replica set config for server discovery & monitoring. A Socket operation timed out error is expected if a driver cannot connect to a mongod instance using the hostnames and ports discovered via the replica set configuration.Possible solutions are:Regards,
Stennie
Code:Socket operation timed outmongodmongodreplicaSet

[User]
Text:
973×557 17.4 KB

Figured out where the firewall is on Oracle, so I added this rule. (Will change the IP range later to only allow trusted IP’s)
But now I get the following error:
Code:2020-02-17T15:30:48.483+0000 E  QUERY    [js] Error: couldn't connect to server 03.mongodb.DOMAIN.nl:27017, connection attempt failed: SocketException: Error connecting to 03.mongodb.DOMAIN.nl:27017 (X.X.X.X:27017) :: caused by :: No route to host :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-02-17T15:30:42.322+0000 F  -        [main] exception: connect failed
2020-02-17T15:30:42.322+0000 E  -        [main] exiting with code 1

[Assistant]
Text:03.mongodb.DOMAIN.nl:27017 (X.X.X.X:27017) :: caused by :: No route to hostNo route to host indicates a networking problem: there currently isn’t a valid network route to communicate with the target IP address.If the target IP in that message is as expected and your firewall rules are open,  one likely cause is that you may be trying to connect to private IPs (for example, 10.* in one of your earlier output examples) from a public IP. Private IPs are only routable within the same local network or VPN.If the destination IPs are definitely not private IPs, this may be a networking or firewall issue to follow up on with your ISP/hosting providers.Regards,
Stennie
Code:No route to host10.*

[User]
Text:Hi @Stennie_X,I took the time to set up a VPN to connect the servers together, but I still get the no route to host error.They can ping each other just fine and connect to each other with ssh.
Code:no route to host> rs.initiate( {    _id : "rs0",    members: [       { _id: 0, host: "01.mongodb.DOMAIN.nl:27017" },       { _id: 1, host: "02.mongodb.DOMAIN.nl:27017" },       { _id: 2, host: "03.mongodb.DOMAIN.nl:27017" }
    ] })
{
        "ok" : 0,
        "errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: 02.mongodb.DOMAIN.nl:27017 failed with Error connecting to 02.mongodb.DOMAIN.nl:27017 (10.8.0.3:27017) :: caused by :: No route to host, 03.mongodb.DOMAIN.nl:27017 failed with Error connecting to 03.mongodb.DOMAIN.nl:27017 (10.8.0.2:27017) :: caused by :: No route to host",
        "code" : 74,
        "codeName" : "NodeNotFound"


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

[System] The following conversation has title: Where is my data stored? and tags: []

[User]
Text:I have specified a directory for my databases, but i cannot see the files. I have created 2 databases, “test” and “eieio”. I can see them at the command prompt using “db”, and i can do CRUD operations on them. But, when i look at my folder in windows explorer, they are not there, neither can i search for them in Windows taskbar search. Can someone tell me where to look and what to look for?Thanks!!
Code:

[Assistant]
Text:They are in the directory specified by your dbpath. However the name of the files do not reflect the name of the collections.
Code:

[Assistant]
Text:just in case it was not set to what you thought you did you can look in the local.startup_log collectionOr slightly modified for brevity:
Code:use local
db.startup_log.find().sort({startTime:-1}).limit(1).pretty()
db.startup_log.find({},{cmdLine:1}).sort({startTime:-1}).limit(1).pretty()
{
	"_id" : "5ca6d0cdf984-1582162763917",
	"cmdLine" : {
		"net" : {
			"bindIpAll" : true
		},
		"replication" : {
			"replSet" : "s0"
		},
		"security" : {
			"authorization" : "enabled",
			"keyFile" : "/keyfile"
		}
	}
}

[Assistant]
Text:mongod has an option to create separate directories for each database. For your existing deployment, you can create separate directories for each database using the option –directoryperdb (and following instructions in the documentation).
Code:mongod

[User]
Text:This is my db folder. I searched documentation for .wt, but tons of info comes up. Is there some page that gives brief overview of these various files and folders that gives some explanation of structure and use?Thanks!
Code:

[Assistant]
Text:That is your database files.What exactly are you trying to achieve?
Code:

[User]
Text:would just like to understand what i am seeing. i have done a lot of MS Access work over the years and i can open tables, see the text in queries, etc. I was just wondering if these various files can be opened with a text editor, which file contains my data, and so forth.Thinking about backup too. Would i just backup everything in the folder and call it a day? Just trying to understand what i am seeing.Thanks!
Code:

[Assistant]
Text:If you are wanting to ad-hoc navigate and query your database you’ll want to use a GUI client like MongoDB Compass or the mongo command line interface.Your instinct on backup is essentially accurate, there are a few other ways and considerations that make good reading https://docs.mongodb.com/manual/core/backups/
Code:mongo

[User]
Text:That makes sense. I tried Compass, it works great. I guess that i was thinking that MongoDB stored data in a text file full of json. Really, i am just trying to get familiar with the workings of Mongo.Thanks!
Code:

[Assistant]
Text:I guess that i was thinking that MongoDB stored data in a text file full of json.MongoDB stores data and indexes on disk in a compressed binary format. Individual documents are represented in BSON, a binary JSON-like serialisation format that supports additional data types such as dates, 32-bit integers, 64-bit integers, 128-bit decimals, ObjectIDs, and binary data.Data is written to disk using block compression for documents and prefix compression for indexes. Compression defaults are configurable at a global level and can also be set on a per-collection and per-index basis during collection and index creation.For further reading that might provide helpful background info, see:Regards,
Stennie
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: What is the best type for a Number? and tags: ['data-modeling']

[User]
Text:In MongodDB atlas there are a variety of options for picking a data type for a Number, however there is no generic Number option, unlike the ability to do so using mongoose to create the schema, so which would be best to use in MongoDB atlas?
Code:

[Assistant]
Text:Hey @Quozzo_CrozzyHow big of a number are you thinking?I think mongoose stores the number as a Int-32 BSONIf you are looking at a large number then use 64-bit Int
If you are looking at financial data and need to be extremely precise then use the Decmial128 which is also a Mongoose type.Hope this helps
Code:number

[Assistant]
Text:As far as I know Mongoose does not natively support long and double data types. “number” is a “schema type”, it just for input validation…It is same on Atlas, these types for input validation, unless you pick Decimal128, mongodb stores everything same way generic number.
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 update first empty object in array? and tags: ['queries']

[User]
Text:I’m trying to create update query for document, which would update first empty object it finds in specified array in that document.For example, document would be something like this:So I would like to update only first empty object in arrayOfObjects with some data, for example { "objectName": "example2", "objectData": "newdata" }. Rest of the document should remain same.I found out how to check if there is empty object in that array, with this kind of code:In above code documentData is whole document returned from MongoDB. However I have feeling that it is possible to have some filter/selector in $set, but I can’t quite put my finger in it.Any help would be appreciated.  I am using nodejs as programming language, if that makes any difference.
Code:{
"_id": 123,
"somekey": "example",
"arrayOfObjects": [
    {
        "objectName": "example1",
        "objectData": "somedata",
    },
    { },
    { },
    { }
],
"otherinfo": "something else"
}
arrayOfObjects{ "objectName": "example2", "objectData": "newdata" }const callback = (element) => element.constructor === Object && Object.entries(element).length === 0;
const index = documentData.arrayOfObjects.findIndex(callback);
documentData$set

[Assistant]
Text:The programming language doesn’t matter since you want the update filter to be applied on the DB and you want the update mutation also to happen in the server.So if your query is for the first document which has an empty object in that array you can query for {arrayOfObjects:{}} now you can update it in a couple of different ways.  You can use the positional operator ($) with $set, you can use arrayUpdate option with set with [index]` or you can use aggregation with $addFields (alias $set) stage in the update pipeline.I’m curious why the empty objects are already present - more common would be to add data as it becomes available via $push. Is this to preallocate a specific number of elements in each array?Asya
Code:{arrayOfObjects:{}}arrayUpdate

[User]
Text:I’m curious why the empty objects are already present - more common would be to add data as it becomes available via $push. Is this to preallocate a specific number of elements in each array?Yes, I want to pre-allocate specific number of elements in array, and keep number of elements static from there on. I was thinking of having element like "maxNumberOfObjects": 4, but counting array elements in many places felt also pretty convenient, so defaulted to that.So if your query is for the first document which has an empty object in that arrayActually, document I would be updating, I know, so I have _id of it at hand. So I can target specific document, and update empty object in arrayOfObjects. Like you said more common way would be to use $push, this is kind of what I want to do, though instead of pushing new object in, updating first empty object, and ideally failing if there are no empty objects. If “nice” failing isn’t possible, I could first check that there is empty object before updating.More traditional database/programming way I would most likely go finding [index] in first query, then make another query which does update. However that update method seems to have arrayFilters which I have feeling could get this done in one query. Didn’t find anyone trying to filter empty object, so trying to figure out how to write such query.So I believe it would be something like:But I’m a bit lost what should be that actual filter there, and a bit unsure how correct is that $set line.
Do you catch my idea here, and have some pointers how to make that update as working one @Asya_Kamsky?
Also if you see some big drawbacks (other than being uncommon way to have empty objects), I’m eager to hear. My idea with this document structure has been that I need less queries and document structure contains meaningful information itself too.
Code:"maxNumberOfObjects": 4_idarrayOfObjects[index]arrayFiltersdb.collection.update(
    { "_id": "abc123" },
    { $set: { "objectName": "example2", "objectData": "newdata" } },
    {
    arrayFilters: $[ how_to_filter_empty_object ]
    }
)

[Assistant]
Text:Would it help to know that you can compare something to {} to match an empty object?I can show example of how to do this with all three methods, just wanted to check if you want to see the answer or prefer to just be pointed towards the answer
Code:{}

[Assistant]
Text:I tried this using the aggregation for the update (MongoDB version 4.2). The query looks for the first empty object in the array and updates it with the new object.This works fine from the Mongo Shell.
Code:NEW_OBJ = { "objectName": "example2", "objectData": "newdata" }

db.collection.updateOne(
    {
        _id: 123,
        arrayOfObjects: { }
    },
    [
        {
            $addFields: {
                // ix is index of the first element which is an empty object
                ix: { $indexOfArray: [ "$arrayOfObjects", { } ] },
                ixs: { $range: [ 0, { $size: "$arrayOfObjects" } ] }
            }
        },
        {
            $project: {
                arrayOfObjects: {
                    $map: {
                        input: "$ixs",
                        in: {
                            $cond: [
                                { $eq: [ "$ix", "$$this" ] },
                                 NEW_OBJ,
                                { $arrayElemAt: [ "$arrayOfObjects", "$$this" ] }
                             ]
                        }
                   }
               }
           }
       }
    ]
)

[User]
Text:Thank you @Prasad_Saya, that looks interesting approach. I’ll give it a go. It looks more complex than I had expected it to be, as I was fiddling around something like this:But I was running into error that $arrayOfObjects wasn’t defined, and was just coming to ask a bit of example from @Asya_Kamsky how that filter works, and am I even in right path.
Code:db.test.update(
   { "_id": "abc123" },
   { $set: { "objectName": "example1", "objectData": "newdata"}},
   { arrayFilters: $arrayOfObjects[ {} ]});
$arrayOfObjects

[Assistant]
Text:I think you were looking for something more likeps edited to fix syntax
Code:db.test.update(
   { "_id": "abc123" },
   { $set: { "arrayOfObjects.$[i]": {"objectName": "example1", "objectData": "newdata"}}},
   { arrayFilters: [ { i: {$eq: {}} } ] }
);

[Assistant]
Text:You can also do it using positional operator:
Code:db.coll.update(
   {_id:x, arrayOfObjects:{}},
   {$set: {“arrayOfObjects.$”:{new:”whatever”}}})

[User]
Text:Thank you very much @Asya_Kamsky, both are nice and clean solutions. Tried both, and I think there is small typo on that arrayFilter example, missing { there maybe? What worked for me is like this (for future references when someone tries same solutions)Both seem to work similarly when there are empty objects which can be updated, giving following results:However when document doesn’t have empty objects, first one still gives Matched: 1, but doesn’t of course modify anything. Second one gives zeroes to both Matched and Modified.So I think I’ll go with first one, and see if I can get that result checked in code, and hop into different usecase if there ain’t empty objects anymore.Thank you once more Asya, this allows me to continue onward in my project.
Code:db.test.update(
   { "_id": "abc123" },
   { $set: { "arrayOfObjects.$[i]": {"objectName": "example1", "objectData": "newdata"}}},
   { arrayFilters: [ { i: { $eq: {} }} ] });
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

[Assistant]
Text:If you add the check for presence of empty object to the query in the first query then the result would be the same - it says I didn’t find a matching record.
Code:

[User]
Text:I must have overlooked how these when I was testing them in mongo shell. Now that I tried implementing in nodejs, I noticed that arrayFilter way actually doesn’t work as intented. Instead of updating only first empty object, it updates all empty objects in that array in given document.As first one seems to be updating only first object, I can work with that. However is there some modification for arrayFilter to match only one/first, or is it actually meant to match all elements in array always?
Code:

[Assistant]
Text:To overcome this issue of updating all the empty objects with the update operation, the aggregation solution is implemented. The aggregation first checks if there is an empty object in the array, then, gets the index of the first empty object, and, replaces that empty object with the supplied new object.The query does look complex, but it is a solution for the requirement.
Code:

[Assistant]
Text:Instead of updating only first empty object, it updates all empty objects in that array in given documentAh, I see what you’re saying - you don’t want to update all the matching entries, just the first one.  Positional update (first syntax) is the one to use then - while aggregation in update works as well (as long as you’re on 4.2+) unfortunately there is no syntax to easily short-circuit from $map iteration over the array - with a small array it’s not a big deal, but for larger arrays it might be noticeably slower.It can actually be done with $concatArrays rather than $map by concatenating using the index (location of the first {} element in the array rather than for iteration but like this:This would go as the second argument to update.  I didn’t run this so I’m sure there’s a paren missing somewhere or an off-by-one error…
Code:$concatArrays$map{}[ {$set:{ arrayOfObjects:{$let: {
     vars: { ix: { $indexOfArray: [ "$arrayOfObjects", { } ] } },
     in: {$concatArrays: [
         {$slice:[ "$arrayOfObjects", 0, "$$ix"] },
         [ { newObjectHere } ],
         {$slice:[ "$arrayOfObjects", {$add:[1, "$$ix"]}, 4] }
     ]
}}}}]
update

[User]
Text:I’ll give that a testing in few days, once I return to that part of project. If I don’t see performance difference between first working one and this arrayFilter one, I might continue using first one. It is much shorter and easier to read  I’m fairly sure that if I need to return that query at later date, or someone new tries to start understanding it, it will be appreciated. That’s however fine example of how powerfull things can be done directly in query, and I might need that at later time. Thank you very much @Asya_Kamsky for taking time with this.
Code:

[Assistant]
Text:This is the same update query I had posted earlier with some refinement:
Code:db.collection.updateOne(
    {
        _id: 123,
        arrayOfObjects: { }
    },
    [
        {
            $set: {
                arrayOfObjects: {
                    $map: {
                        input: { $range: [ 0, { $size: "$arrayOfObjects" } ] },
                        in: {
                            $cond: [
                                { $eq: [ { $indexOfArray: [ "$arrayOfObjects", { } ] }, "$$this" ] },
                                { "objectName": "example2", "objectData": "newdata" }, // this is the new object to be inserted
                                { $arrayElemAt: [ "$arrayOfObjects", "$$this" ] }
                             ]
                        }
                   }
               }
           }
       }
    ]
)

[User]
Text:Thank you @Prasad_Saya, that query starts to look like understandable now. I’ll try to give it a go as well… Though at a glance it looks like having similar elements as Asya’s previous query:
That one seemed to work without need to do any $map, updating only first empty object it found, so is it necessary to have this more complex query Prasad? As I haven’t tested yet, I don’t know do they behave differently in edge situations… like when there is no arrayOfObjects{} in document for some reason, or if it doesn’t have any empty objects. Or performance wise big differences? In my current use case arrayOfObjects is usually around 10 elements, most likely at maximum rare cases 30-50 elemenets, so quite small. But concurrent operations by different users to different documents can be significant, if this product takes off properly. But I’ll test them out…
Code:$map

[Assistant]
Text:Note that in all examples, you should include the test for {arrayOfObjects:{}} so that it’s guaranteed that there is an empty object in the array.
Code:{arrayOfObjects:{}}

[Assistant]
Text:@Prasad_Saya you are correct that it’s the same approach with aggregation update, I was simply pointing out that $map is less efficient in the case where you want to replace a single element in an array.
Code:

[Assistant]
Text:Yes, iterating over the entire array (i.e., using $map) is less efficient just to update one array element (especially if the array has a lot of elements). Also, noted that the update is for one document only (as it is queried by its _id).
Code:$map_id


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

[System] The following conversation has title: updateOne vs replaceOne performance and tags: ['performance']

[User]
Text:Hey community,I’ve been developing a pattern for my application where I write get the document, edit it in memory the whole document back to the db.
This is really convenient because I don’t need to make a custom update for every bit of functionality. And this is becomes really testable in my app.From what I can see there are two ways to update a whole collection
collection.updateOne({_id: id}, {$set: theDocument})
or
collection.replaceOne({_id: id}, {theDocument})Is any method better or faster than the other?
Also I realise this might not be safe, but these documents are not operated on many times within a small time frame, for sensitive updates I write atomic updating functions.
Code:collection.updateOne({_id: id}, {$set: theDocument})collection.replaceOne({_id: id}, {theDocument})

[Assistant]
Text:Honestly I would insert the whole document as new, and then delete the old one.
Code:

[Assistant]
Text:If… these documents are not operated on many times within a small time frameyou should not worry about being faster.  That being written.  If I remember correctly, existing fields with unchanged values are not modified during $set (sorry I do not remember exactly where I read that).  If those unchanged fields are part of an index the replaceOne or insertThenDelete might have a much bigger impact than updateOne.
Code:

[User]
Text:But then you can’t use the same _id, because its a unique index and now that is 2 operations. I don’t think it’s an ideal solution.
Code:

[Assistant]
Text:Hi @Ihsan_Mujdeci,I’d strongly encourage not doing an entire document update or replacement.Sending an entire document to update one or two fields (when many more fields remain the same) can quickly cause scalability problems. For example, as documents grow, sending an entire document across the network is a lot of unnecessary network traffic. Also, the oplog becomes unnecessarily bloated.Using db.collection.updateOne with the appropriate operator (e.g. $set) is smaller and efficient when only updating fields that change.Justin
Code:db.collection.updateOne$set


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

[System] The following conversation has title: Given transaction number does not match any in-progress transactions and tags: ['transactions']

[User]
Text:I am getting above error when trying to create transactions for multiple orders and I am using async/await to create multiple transactions for each order one by one.Kindly help me to solve this error.
Code:given transaction number does not match any in-progress transactions

[Assistant]
Text:Hi @Naif_Almuqbel, welcome!In order to help others answer your question, could you answer the following to provide more information:Regards,
Wan.
Code:TransientTransactionError

[User]
Text:Hi @wan,I have provided my configuration below:MongoDB server version is 4.2.3 and it is hosted on atlas.
Driver - NodeJS and version v12.13.1No TransientTransactionError is occuring and actual error is Given transaction number 2 does not match any in-progress transactions. The active transaction number is 1Also I am not performing any operations like creating collection, an index, dropping collection and other types of DDL operationsI have provided my code below.
I am running a job to update order status as completed, creating and updating documents in transaction.
Code:TransientTransactionErrorfunction checkOrder() {
    const timeStampNow = new Date().getTime();
    const query = {
             status: {
                     $in: [ Constants.PAID_PAYMENT,
                            Constants.RESCHEDULE_REQUEST_ACCEPTED ]
             },
             expiryDate: {
                   $lte: new Date(timeStampNow)
             },
            isActive: true
       };

  await Request.find(query, async (err, docs) => {
    if (err || Utility.isEmptyObject(docs)) {
        // console.log('error ' + err);
    }
    else {
        try {
            for (let i in docs) {
                let requestData = docs[i];

                const data = {
                    referenceId: requestData.referenceId,
                    status: Constants.COMPLETED
                };

                await updateRequestCronJob(data);
            }
        }
        catch (e) {
            console.log('CRON: error -job', e);
        }
    }
  });
}

async function updateRequestCronJob(data) {

       const status = data.status; // to be updated
       const referenceId = data.referenceId;

       const query = { referenceId: referenceId, isActive: true };

      await Request
               .findOne(query)
               .then(async (request) => {
                       let session = await mongoose.startSession();
                       session.startTransaction();
                   try {
                          const opts = { session };
                          const currentTime = Utility.currentTimeNow();

                          let transactionId = Utility.generateUniqueRandomNumber();

                          let transactionBody = {
                                    transactionId: transactionId,
                                     requestId: referenceId
                             };

            let transactionsAr = [];
            let artistIncome;

            // deduct money from admin & credit to artist

            let orderAmount = request.paymentAmount;
            const artistId = request._artistId._id;

            let commissionAmount = Utility.getCompletionCommission(orderAmount,
                request.commissionPercent);

            artistIncome = orderAmount - commissionAmount;

            transactionBody['amount'] = artistIncome;
            transactionBody['status'] = Constants.TRANSACTION_STATUS_CREDITED;
            transactionBody['from'] = Constants.ADMIN_MONGO_ID;
            transactionBody['fromDesc'] = Constants.TRANSACTION_FROM_SERVICE_INCOME;
            transactionBody['to'] = artistId;
            transactionBody['desc'] = Constants.ARTIST_SERVICE_INCOME;
            transactionBody['type'] = Constants.TRANSACTION_TYPE_DEBIT;
            transactionBody['mode'] = Constants.TRANSACTION_MODE_WALLET;
            transactionBody['createdAt'] = Utility.currentTimeNow();

            transactionsAr.push(transactionBody);

            // save completion commission
            transactionBody = {};

            transactionBody['transactionId'] = Utility.generateUniqueRandomNumber();
            transactionBody['requestId'] = referenceId;

            transactionBody['amount'] = commissionAmount;
            transactionBody['status'] = Constants.TRANSACTION_STATUS_JAMELAH_COMPLETION_COMMISSION;
            transactionBody['from'] = Constants.ADMIN_MONGO_ID;
            transactionBody['to'] = Constants.ADMIN_MONGO_ID;
            transactionBody['desc'] = Constants.COMPLETION_COMMISSION;
            transactionBody['type'] = Constants.TRANSACTION_TYPE_CREDIT;
            transactionBody['mode'] = Constants.TRANSACTION_MODE_WALLET;
            transactionBody['createdAt'] = Utility.currentTimeNow();

            transactionsAr.push(transactionBody);

            await Transaction.create(transactionsAr, opts)
                .then(res => {
                    //console.log(res);
                    if (Utility.isEmptyObject(res)) {
                        throw new Error('Error in creating transaction.');
                    }
                });

            // b) deposit service amount in artist wallet
            await User.findOneAndUpdate({ _id: artistId },
                {
                    $inc: { 'wallet.balance': artistIncome }
                },
                { session, new: true }).
                then(res => {
                    //console.log(res);
                    if (Utility.isEmptyObject(res)) {
                        throw new Error('Error in crediting artist wallet.');
                    }
                    return res;
                });

            let orderBody = {
                status: status,
                updatedAt: currentTime,
                reviewNotificationTime: Utility.addHoursToCurrentTime(process.env.NOTIFICATION_HOURS_AFTER_COMPLETION ||
                    Config.NOTIFICATION_HOURS_AFTER_COMPLETION),
                artistIncome: artistIncome
            };

            await Request.findOneAndUpdate(
                {
                    referenceId: referenceId
                },
                {
                    $set: orderBody,
                    $push: {
                        statusStages: {
                            status: status,
                            time: currentTime
                        }
                    }
                },
                opts)
                .then(res => {
                    if (Utility.isEmptyObject(res)) {
                        throw new Error('Error in updating order.');
                    }
                    return res;
                });

            await session.commitTransaction();
            session.endSession();
            return true;
        }
        catch (error) {
            await session.abortTransaction();
            session.endSession();
            throw error;
        }
    })
    .catch(e => {
        return;
    });
}

[Assistant]
Text:Thanks for providing more information and code snippets.It is likely that you’re not seeing the full error message because at the end of function updateRequestCronJob  the catch does not throw error. The full error message should look something similar as below:This is likely related to mongoose issue #7502, and SERVER-36428.You can try to incorporate logic to retry the transaction for transient errors, and also retry the commit for unknown commit error. For example:See more information and snippets on Transactions In Applications: Core API (Switch the code tab to Node.JS)Regards,
Wan.
Code:updateRequestCronJob catch{ MongoError: Given transaction number 3 does not match any in-progress transactions. The active transaction number is 2
    at Connection.<anonymous> (/vbox/mongo/nodejs/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:450:61)
    at Connection.emit (events.js:182:13)
    at processMessage (/vbox/mongo/nodejs/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connection.js:384:10)
    at Socket.<anonymous> (/vbox/mongo/nodejs/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connection.js:586:15)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onread (net.js:639:20)
  errorLabels: [ 'TransientTransactionError' ],
  operationTime:
   Timestamp { _bsontype: 'Timestamp', low_: 8, high_: 1582506018 },
  ok: 0,
  errmsg:
   'Given transaction number 3 does not match any in-progress transactions. The active transaction number is 2',
  code: 251,
  codeName: 'NoSuchTransaction',
  '$clusterTime':
   { clusterTime:
      Timestamp { _bsontype: 'Timestamp', low_: 14, high_: 1582506018 },
     signature: { hash: [Binary], keyId: 0 } },
  name: 'MongoError',
  [Symbol(mongoErrorContextSymbol)]: {} }
async function runTransactionWithRetry(txnFunc, data) {
  let session = await mongoose.startSession();
  session.startTransaction();
  try {
    await txnFunc(data, session);
  } catch (error) {
    console.log('Transaction aborted. Caught exception during transaction.');

    // If transient error, retry the whole transaction
    if (error.errorLabels && error.errorLabels.indexOf('TransientTransactionError') >= 0) {
      console.log('TransientTransactionError, retrying transaction ...');
      await runTransactionWithRetry(txnFunc, data);
    } else {
        session.abortTransaction();
        console.log("runTransactionWithRetry error: ");
        throw error;
    }
  }
}

async function commitWithRetry(session) {
  try {
    await session.commitTransaction();
    console.log('Transaction committed.');
  } catch (error) {
    if (
      error.errorLabels &&
      error.errorLabels.indexOf('UnknownTransactionCommitResult') >= 0
    ) {
      console.log('UnknownTransactionCommitResult, retrying commit operation ...');
      await commitWithRetry(session);
    } else {
      console.log('Error during commit ...');
      throw error;
    }
  }
}


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

[System] The following conversation has title: Using a nodejs script to connect to localhost 27017 and tags: []

[User]
Text:I have MongoDB installed and I can view it through Compass. Now i want to create an Express script that will connect to MongoDB and show data on my browser. I am working through the Web Developers Bootcamp on Udemy, and so far i have this:When I run this from PowerShell, using: node ./app.js, I get “i heard you” (from my listen function above. So I am apparently “connected” to port 27017. Now I want to see “i heard you” in the browser. I assume it should look, in browser address bar, 192.168.0.1/localhost:27017, with my “i heard you” in the browser window.So sorry if this is all over the place.Thanks for any help!
Code:var express = require('express');
var app = express();

// "/" => "Hi there"
app.get('/', function(req, res) {
  res.send('hi there');
});

app.listen(27017, function() {
  console.log('i heard you');
});
node ./app.js

[Assistant]
Text:i want to create an Express script that will connect to MongoDB and show data on my browser.Okay, this about using Express (a web framework for NodeJS) and MongoDB. I put together this basic code from samples at: Getting started with Express and Quick Start Examples with MongoDB NodeJS DriverThe code works fine, and try to follow it by perusing the code comments.
Code:// app.js (or index.js)
const express = require('express')
const app = express()
const port = 3000

app.listen(port, () => console.log('Example app listening on port ' + port))

// This line of code is for printing Hello World! in the browser,
// when you enter in the browser url bar: http://localhost:3000/
app.get('/', (req, res) => res.send('Hello World!'))

// This variable is populated in the findDocuments function (see below "Using Mongo")
var mongoDocsToDisplay = null;

// This line of code will print the collection's documents in the browser,
// when you enter in the browser url bar: http://localhost:3000/mongo
app.get('/mongo', (req, res) => res.send(
    mongoDocsToDisplay
));

// Using MongoDB:

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const url = 'mongodb://localhost:27017';

const dbName = 'test';
const client = new MongoClient(url, { useNewUrlParser: true, useUnifiedTopology: true } );

// Connect to MongoDB server, run the findDocuments function and close the connection.
client.connect(function(err) {

    assert.equal(null, err);
    console.log('Connected successfully to MongoDB server on port 27017');
    const db = client.db(dbName);

    findDocuments(db, function() {
        client.close();
    });
});

const findDocuments = function(db, callback) {

  const collection = db.collection('test');

  collection.find({}).toArray(function(err, docs) {
    assert.equal(err, null);
    console.log('Found the following documents:');
    console.log(docs)
	mongoDocsToDisplay = docs;
    callback(docs);
  });
}

[User]
Text:This is helpful! Thanks!
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 documents by certain date (like until yesterday) and tags: ['queries']

[User]
Text:I need to remove the data in one of the collection in dev enrionment but only remove the data that is created until yesterday.id field  documents are numeric values(like 1,2,3 etc)… i am working in mongo shell looking for help on this. There are no date fields in my json that i could use filter criteria to remove.
Code:

[Assistant]
Text:@nagaraju_vooraThere are no date fields in my json that i could use filter criteria to remove.id field documents are numeric values(like 1,2,3 etc)This may make things difficult.However…the collection in dev enrionmentAs this is a dev environment and I am assuming by ‘yesterday’ you mean any giving yesterday and not exactly Feb 18? Could you not just clear the database and await fresh data?I could be wrong but I think you would need some date field stored in the documents you wish to remove by a certain date
Code:

[Assistant]
Text:Timestamp would be ideal. If _id is the default ObjectID then you can use that(but I think you said this was an int, unless that was id not _id):sorting on an _id field that stores ObjectId values is roughly equivalent to sorting by creation time.
https://docs.mongodb.com/manual/reference/bson-types/#objectidPossibly also using $natural in sort.
Code:_idObjectId$natural

[Assistant]
Text:I am assuming you have a field called “created_on” and it is date field, so you can subtract 24 hours and find the dates less than that value.
Code:{
    "created_on": {
        "$lte": new Date((new Date().getTime() - (24 * 60 * 60 * 1000)))
    }
}

[User]
Text:I need ability remove the documents for a given date…my documents in mongo sb collection does not have any date related elements
Code:

[Assistant]
Text:I really do not understand.  You do not have or want any field with a date in your documents yet you want to be able to delete document for a given date.  But this is comparable to I want delete all Blue items but my items have no colour.  Impossible
Code:

[Assistant]
Text:Not entirely impossible in this case. It depends. I gave two possible alternatives when there is no deicated timestamp field.Given a replica set and using the oplog I am sure there are other possibilities.Is the dataset poorly designed for this operation? Almost certainly.
Code:

[Assistant]
Text:Timestamp would be ideal. If _id is the default ObjectID then you can use that(but I think you said this was an int, unless that was id not _id):id field documents are numeric values(like 1,2,3 etc)…Possibly also using $natural in sort.The  $natural  parameter returns items according to their natural order within the database. This ordering is an internal implementation feature, and you should not rely on any particular structure within it.I am assuming you have a field called “created_on” and it is date fieldI think this can only be assumed if @nagaraju_voora was using Mongoose as an ORM which adds created_at with timestampsI think the best way is to add a created_at field or some sort of date field. Keeping in mind this is only a dev environment things should be easy to change no?
Code:$natural$naturalcreated_atcreated_at

[Assistant]
Text:Hey @nagaraju_voora while I can do this, you really probably shouldn’t. At least not this way, I strongly agree with the previous posters that the prefered method would be to add a timestamp to your documents. That being said, you can probably do what you’ve asked using the oplogThis code is incredibly hacky and I do not recommend you run it in any environment, not even dev… but as a purely academic exercise of “is it possible”, then the answer is yes.You can find out more about the oplog in the docs
Code:import pymongo
from bson.objectid import ObjectId
from datetime import datetime, timedelta

client = pymongo.MongoClient()
oplog = client.local.oplog.rs
db = client['dev']
previous_day = datetime.now() - timedelta(days=1)

ops = oplog.find({"ns":"dev.users", "op": "i", "wall": {"$lt": previous_day}})

for op in list(ops):
    db["users"].delete_one({"_id": ObjectId(op['o']['_id'])})

[Assistant]
Text:I think you just filled the:Given a replica set and using the oplog I am sure there are other possibilities.
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: HTTP: Error receiving data -- Connection reset by peer and tags: ['configuration']

[User]
Text:Hi,Since I’ve rebooted my server yesterday I’m getting this error:mongodb’ failed protocol test [HTTP] at [localhost]:27017/ [TCP/IP] – HTTP: Error receiving data – Connection reset by peer‘mongodb’ start: ‘/usr/bin/sudo mongod --dbpath=/var/lib/mongodb’Tried a couple of thing but no luck.Also checked with curl -v localhost:27017 and output below:GET / HTTP/1.1
Host: localhost:27017
User-Agent: curl/7.58.0
Accept: /Any input or help will be much appreciated.Thanks.
Code:

[Assistant]
Text:What O/S version are you running and how do you normally start your MongoDB service? Was this a clean reboot or an unexpected/forced restart?The error messages suggest you are trying to connect to localhost:27017 but the MongoDB service isn’t running. If this coincides with rebooting your server, the MongoDB service may not be set to run on startup or has perhaps encountered an error. I would start by checking the MongoDB server logs.mongodb’ failed protocol test [HTTP] at [localhost]:27017/ [TCP/IP]Is this output from monit? It is unusual to do an HTTP check for mongod on the default port since the server uses the MongoDB Wire Protocol, but if the server is accessible the result for an HTTP request should be similar to: “It looks like you are trying to access MongoDB over HTTP on the native driver port.”.Regards,
Stennie
Code:localhost:27017monitmongod

[User]
Text:What O/S version are you running and how do you normally start your MongoDB service? Was this a clean reboot or an unexpected/forced restart?Currently running Ubuntu 18 and it looks like it’s not set to start manually, I took over from the previous person. It was a unexpected/forced restart.The error messages suggest you are trying to connect to localhost:27017 but the MongoDB service isn’t running. If this coincides with rebooting your server, the MongoDB service may not be set to run on startup or has perhaps encountered an error. I would start by checking the MongoDB server logs.Yes, that’s correct but the mongodb service is down, killed the pid and tried starting the service but still fails, should I post the logs here as well?Is this output from monit ? It is unusual to do an HTTP check for mongod on the default port since the server uses the MongoDB Wire Protocol, but if the server is accessible the result for an HTTP request should be similar to: “It looks like you are trying to access MongoDB over HTTP on the native driver port.”.Yes, it’s uning monit Also not sure why it was setup that way, like I mentioned I took over from anoteher guy.What should I change or do to fix this issue.Much appreciated.
Code:localhost:27017monitmongod

[User]
Text:Hi,I followed this link but still no go for me Any help would be appreciated.Thanks.
Code:

[Assistant]
Text:Yes, that’s correct but the mongodb service is down, killed the pid and tried starting the service but still fails, should I post the logs here as well?You could post relevant lines from the logs if it isn’t obvious why the MongoDB process isn’t starting successfully.What command line are you using to start the MongoDB service? If the installation used the official MongoDB packages you should be able to use systemctl: Start MongoDB.The default log file location is /var/log/mongodb/mongod.log. If the mongod process is unable to start successfully, the last log lines should provide some indication of the reason (for example file permissions or integrity problems).Regards,
Stennie
Code:systemctl/var/log/mongodb/mongod.logmongod

[User]
Text:You could post relevant lines from the logs if it isn’t obvious why the MongoDB process isn’t starting successfully.Here is the lst lines of the log file: (Path : cat /var/log/mongodb/mongodb.log)
2020-02-19T08:47:17.620+0200 I CONTROL  [main] ***** SERVER RESTARTED *****
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] MongoDB starting : pid=25072 port=27017 dbpath=/var/lib/mongodb 64-bit host=dis002-truservcomm-jhb1-001
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] db version v3.6.3
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] allocator: tcmalloc
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] modules: none
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] build environment:
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten]     distarch: x86_64
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] options: { config: “/etc/mongodb.conf”, net: { bindIp: “127.0.0.1”, port: 27017, unixDomainSocket: { pathPrefix: “/run/mongodb” } }, security: { authorization: “disabled” }, setParameter: { enableLocalhostAuthBypass: “0” }, storage: { dbPath: “/var/lib/mongodb”, journal: { enabled: true } }, systemLog: { destination: “file”, logAppend: true, path: “/var/log/mongodb/mongodb.log” } }
2020-02-19T08:47:17.629+0200 I STORAGE  [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /var/lib/mongodb, terminating
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] now exiting
2020-02-19T08:47:17.629+0200 I CONTROL  [initandlisten] shutting down with code:100What command line are you using to start the MongoDB service? If the installation used the official MongoDB packages you should be able to use systemctl : Start MongoDB.I’m using this command : sudo service mongodb start (or status) but still fails… This is the output of the command you mentioned:
user@server:~$ sudo systemctl start mongodb (Works)
user@server:~$ sudo systemctl start mongod
Failed to start mongod.service: Unit mongod.service not found.The default log file location is /var/log/mongodb/mongod.log . If the mongod process is unable to start successfully, the last log lines should provide some indication of the reason (for example file permissions or integrity problems).Weird, had a look at the log file location but this is the output:
sudo tail -f /var/log/mongodb/mongod.log
tail: cannot open ‘/var/log/mongodb/mongod.log’ for reading: No such file or directoryPlease let me know if you need more details as well.Much appreciated.
Code:systemctl/var/log/mongodb/mongod.logmongod

[Assistant]
Text:db version v3.6.3You should plan to install the latest minor release (currently 3.6.17) as there have been a lot of improvements and stability fixes. A minor release in the same series (3.6.x) does not introduce any compatibility changes.Attempted to create a lock file on a read-only directory: /var/lib/mongodbYou need to fix the permissions on /var/lib/mongodb to match the user you are running mongod as.For example, assuming  mongodb  user and group: sudo chmod -R mongodb:mongodb /var/lib/mongodb.I’m using this command : sudo service mongodb start (or status) but still fails…If service works, that’s fine. systemctl is the equivalent of the service command for systemd which is the usual service manager for Ubuntu 18.Given the older server version (3.6.3) and that you are starting the service using mongodb (rather than mongod) I suspect you have installed Ubuntu’s MongoDB package rather than the officially maintained MongoDB package for Ubuntu.There are some differences in default configuration values between the two packages (such as service name and default paths. I’d recommend using the version from MongoDB as it is more actively maintained and in sync with the server documentation, but you can plan that change after you get your service running successfully.Regards,
Stennie
Code:/var/lib/mongodbmongodmongodbsudo chmod -R mongodb:mongodb /var/lib/mongodbservicesystemctlservicesystemdmongodbmongod

[User]
Text:You should plan to install the latest minor release (currently 3.6.17) as there have been a lot of improvements and stability fixes. A minor release in the same series (3.6.x) does not introduce any compatibility changes.Okay, I will update mongodb to the latest version.You need to fix the permissions on /var/lib/mongodb to match the user you are running mongod as.For example, assuming mongodb user and group: sudo chmod -R mongodb:mongodb /var/lib/mongodb .I’ve done this now and mongodb service still fails. In the log is only entries from 2019/12 nothing to date.If service works, that’s fine. systemctl is the equivalent of the service command for  systemd  which is the usual service manager for Ubuntu 18.I’ve ran the “sudo service mongodb start” command, not failing but service still down. Removed the mongodb.lock file as well.I really have a battle with this, but thank for your help so far.Let me know what other details you need from me.Much appreciated.
Code:/var/lib/mongodbmongodmongodbsudo chmod -R mongodb:mongodb /var/lib/mongodbservicesystemctlservicesystemd

[Assistant]
Text:I’ve done this now and mongodb service still fails. In the log is only entries from 2019/12 nothing to date.Having a sample of the logs like in the previous post is about the only way to give meaningful help. For example it was very obvious there was/is a permissions error on the data directory.
Code:

[User]
Text:Having a sample of the logs like in the previous post is about the only way to give meaningful help. For example it was very obvious there was/is a permissions error on the data directory.2020-02-19T14:01:59.251+0200 I CONTROL  [main] ***** SERVER RESTARTED *****
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] MongoDB starting : pid=22521 port=27017 dbpath=/var/lib/mongodb 64-bit host=dis002-truservcomm-jhb1-001
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] db version v3.6.3
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] allocator: tcmalloc
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] modules: none
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] build environment:
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten]     distarch: x86_64
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] options: { config: “/etc/mongodb.conf”, net: { bindIp: “127.0.0.1”, port: 27017 }, security: { authorization: “disabled” }, setParameter: { enableLocalhostAuthBypass: “0” }, storage: { dbPath: “/var/lib/mongodb”, journal: { enabled: true } }, systemLog: { destination: “file”, logAppend: true, path: “/var/log/mongodb/mongodb.log” } }
2020-02-19T14:01:59.259+0200 I STORAGE  [initandlisten] exception in initAndListen: Location28596: Unable to determine status of lock file in the data directory /var/lib/mongodb: boost::filesystem::status: Permission denied: “/var/lib/mongodb/mongod.lock”, terminating
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] now exiting
2020-02-19T14:01:59.259+0200 I CONTROL  [initandlisten] shutting down with code:100I tried to upgrade from 3.6.3 to 3.6.17 but I broke it now, this is the error message I got:sudo systemctl status mongodbFeb 19 14:01:59 dis002-truservcomm-jhb1-001 systemd[1]: Starting LSB: An object/document-oriented database…
Feb 19 14:01:59 dis002-truservcomm-jhb1-001 mongodb[22500]:  * Starting database mongodb
Feb 19 14:02:00 dis002-truservcomm-jhb1-001 mongodb[22500]:    …fail!
Feb 19 14:02:00 dis002-truservcomm-jhb1-001 systemd[1]: mongodb.service: Control process exited, code=exited status=1
Feb 19 14:02:00 dis002-truservcomm-jhb1-001 systemd[1]: mongodb.service: Failed with result ‘exit-code’.
Feb 19 14:02:00 dis002-truservcomm-jhb1-001 systemd[1]: Failed to start LSB: An object/document-oriented database.Also if I try to “sudo apt install -y mongodb” I get this:Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:The following packages have unmet dependencies:
mongodb-org-shell : Conflicts: mongodb but 1:3.6.3-0ubuntu1.1 is to be installed
Conflicts: mongodb-clients but 1:3.6.3-0ubuntu1.1 is to be installed
Conflicts: mongodb-server but 1:3.6.3-0ubuntu1.1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.Any help would be appreciated.Thanks.
Code:

[Assistant]
Text:2020-02-19T14:01:59.259+0200 I STORAGE [initandlisten] exception in initAndListen: Location28596: Unable to determine status of lock file in the data directory /var/lib/mongodb: boost::filesystem::status: Permission denied: “/var/lib/mongodb/mongod.lock”, terminatingYou still have a permission issue with the files/folders. Assuming mongodb as the uid/guid make sure you run @Stennie_X’s chown command extra ateention to the -RFor upgrading from ubuntu to mongodb-org-* you cannot simply add the repo and install. You will have to remove the Ubuntu version(s).  I’ll see if there is a relevant doc somewhere. Note:  Make sure this is not the only copy. You should have a backup or other running healthy replicas.
Code:

[User]
Text:You still have a permission issue with the files/folders. Assuming mongodb as the uid/guid make sure you run @Stennie’s chown command extra ateention to the -RI have run it -R but keeps changes back, I’m a user and not root, sudo the whole time, could that be an issue?
Code:

[Assistant]
Text:This should be of some help:
Code:

[User]
Text:Looks like I fixed the error but still on 3.6.3 but when I try starting the service is still fails:sudo service mongodb status
mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2020-02-19 14:16:52 SAST; 3s ago
Docs: man:mongod(1)
Process: 27493 ExecStart=/usr/bin/mongod --unixSocketPrefix={SOCKETPATH} --config {CONF} $DAEMON_OPTS (code=exited, status=48)
Main PID: 27493 (code=exited, status=48)Feb 19 14:16:52 dis002-truservcomm-jhb1-001 systemd[1]: Started An object/document-oriented database.
Feb 19 14:16:52 dis002-truservcomm-jhb1-001 systemd[1]: mongodb.service: Main process exited, code=exited, status=48/n/a
Feb 19 14:16:52 dis002-truservcomm-jhb1-001 systemd[1]: mongodb.service: Failed with result ‘exit-code’.
Code:

[User]
Text:This is the last output of the mongodb directory:drwx------  2 mongodb mongodb    4096 Feb 19 13:42 journal/
-rw-------  1 mongodb mongodb   36864 Feb 19 13:41 _mdb_catalog.wt
-rw-------  1 mongodb mongodb       0 Feb 19 14:16 mongod.lock
-rw-------  1 mongodb mongodb   36864 Feb 19 13:42 sizeStorer.wt
-rw-------  1 mongodb mongodb     114 Feb 14 14:42 storage.bson
-rw-------  1 mongodb mongodb      48 Feb 14 14:42 WiredTiger
-rw-------  1 mongodb mongodb    4096 Feb 19 13:41 WiredTigerLAS.wt
-rw-------  1 mongodb mongodb      21 Feb 14 14:42 WiredTiger.lock
-rw-------  1 mongodb mongodb    1057 Feb 19 13:42 WiredTiger.turtle
-rw-------  1 mongodb mongodb  217088 Feb 19 13:42 WiredTiger.wt
Code:

[Assistant]
Text:48 A newly started  mongod  or  mongos  could not start listening for incoming connections, due to an error.More is probably in logs or via journalctl -u mongod
Code:48mongodmongosjournalctl -u mongod

[User]
Text:Ran the command with output:sudo journalctl -u mongod
– Logs begin at Tue 2019-07-16 21:43:12 SAST, end at Wed 2020-02-19 14:27:28 SAST. –
– No entries –
Code:

[Assistant]
Text:Boo. Regular log file ?
Code:

[User]
Text:tail -f /var/log/mongodb/mongodb.log
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] allocator: tcmalloc
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] modules: none
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] build environment:
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten]     distarch: x86_64
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] options: { config: “/etc/mongodb.conf”, net: { bindIp: “127.0.0.1”, port: 27017, unixDomainSocket: { pathPrefix: “/run/mongodb” } }, security: { authorization: “disabled” }, setParameter: { enableLocalhostAuthBypass: “0” }, storage: { dbPath: “/var/lib/mongodb”, journal: { enabled: true } }, systemLog: { destination: “file”, logAppend: true, path: “/var/log/mongodb/mongodb.log” } }
2020-02-19T14:29:16.596+0200 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] now exiting
2020-02-19T14:29:16.596+0200 I CONTROL  [initandlisten] shutting down with code:48Looks the same as previous log file with error code 48 …
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: 'not master and slaveOk=false' error connecting with Compass and tags: []

[User]
Text:Getting this error connecting with Compass!An error occurred while loading navigation: ‘not master and slaveOk=false’: It is recommended to change your read preference in the connection dialog to Primary Preferred or Secondary Preferred or provide a replica set name for a full topology connection.Screenshot_2019-10-09_20-47-27|636x500
Code:

[Assistant]
Text:Try turning on SRV. Click the SRV button in Compass to turn it on and then connect.
Code:

[Assistant]
Text:Hi @Milo_98897It might be due to some network related issue.Can you please make sure you are able to ping the cluster?ping cluster0-shard-00-00-jxeqq.mongodb.netAnd also please verify that port 27017 is not blocked by clicking http://portquiz.net:27017 On some occasions, even though the above mentioned tests passes, network is still a problem. So please make sure you are not connected to any vpn and firewall/antivirus is disabled. You can also try to connect from some other network such as your home network  .Hope it helps!If the issue still persists please feel free to get back to us. Happy Learning Thanks,
Shubham Ranjan
Curriculum Support Engineer
Code:

[Assistant]
Text:not master and slaveOk=falseI doubt this is a networking issue but I could be wrong.Based on the error message:Therefore, the only two options I can see is, use the port number belonging to the Primary, or if you don’t know what the other ports are, use SRV.Another student on another thread reported that the Primary for this replica set (if I remember correctly) keeps changing.
Code:

[User]
Text:SRV causes Compass to not see the Mongod instance.Thanks for your reply.  After trying again this morning (with absolutely no changes on my end, same saved ‘favorite’ connection) the problem seems to have resolved, and i can successfully connect.
Code:

[User]
Text:I had of course already checked the ping, which showed all packets successful.Thanks for your reply.  After trying again this morning (with absolutely no changes on my end, same saved ‘favorite’ connection) the problem seems to have resolved, and i can successfully connect.
Code:

[User]
Text:Thanks for your reply.  After trying again this morning (with absolutely no changes on my end, same saved ‘favorite’ connection) the problem seems to have resolved, and i can successfully connect.
Code:

[Assistant]
Text:SRV causes Compass to not see the Mongod instance.Ok. SRV isn’t setup in this Cluster.
Code:

[Assistant]
Text:Hi @007_jb,I doubt this is a networking issue but I could be wrong.In Compass, network related issues manifest in so many ways that it is hard to keep it out of the consideration when debugging any issue and it is always preferred to make sure that at least these two basics tests are passing before going any further.Based on the error message:27017 is the port number on which the clusters are running. All the nodes in the Cluster0-shard-0 replica set which we use in our M001 : MongoDB Basics course runs on the same port i.e. 27017.You can easily verify this by connecting to the cluster from the mongo shell and then running the command rs.status()Yes, this is correct that the secondaries will not serve the read requests if the slaveOk property for the current connection has been set to false but for this replica set it does not apply because this property has been set to true and read from secondaries are permissible.Screenshot_2019-10-09_20-47-27|636x500In your connection string if you have included the name of the replica set along with any of its members host and port address, you should not worry about which node is the primary because it will always connect you to the primary.In this screenshot, I can see that the replica set name has been provided so which node is the primary is not of any concern here.Another student on another thread reported that the Primary for this replica set (if I remember correctly) keeps changing.Yes, the primary nodes keeps on changing from time to time due to some very obvious reasons. The thread that you are referring to here was for one of our student’s sandbox cluster.Ok. SRV isn’t setup in this Cluster.You can totally connect to the atlas class cluster using the SRV Records as it has been already configured for the same. For doing that please use the connection string mentioned below and select the SRV Record option.Hope it helps. BTW, I like your debugging style and your engagement with the community. Keep up the good work Thanks,
Shubham Ranjan
Curriculum Support Engineer
Code:rs.status()slaveOkcluster0-jxeqq.mongodb.net

[Assistant]
Text:27017 is the port number on which the clusters are running. All the nodes in the Cluster0-shard-0 replica set which we use in our M001 : MongoDB Basics course runs on the same port i.e. 27017 .I didn’t take this course so I was none the wiser about the setup. I was expecting the setup to be similar to all other courses that use different ports per node. And I can now see that it’s running on the same port with different host names after login in yesterday for the first time.Yes, this is correct that the secondaries will not serve the read requests if the slaveOk property for the current connection has been set to false but for this replica set it does not apply because this property has been set to true and read from secondaries are permissible.Good to know for future debugging! cluster0-jxeqq.mongodb.netGood to know too! You guys don’t seem to recommend this option most times. Any particular reasons?Hope it helps. BTW, I like your debugging style and your engagement with the community. Keep up the good work Thanks! Do what we can to help!
Code:slaveOk

[Assistant]
Text:Hi @007_jb,Good to know too! You guys don’t seem to recommend this option most times. Any particular reasons?When the videos were recorded, Compass did not have this functionality. At the moment, we do not recommend this because it may create unnecessary confusion among the learners.Thanks,
Shubham Ranjan
Curriculum Support Engineer
Code: