Closed gom3441 closed 6 years ago
You must run a MongoDB replica set to use transactions. Check out run-rs for this. Here's Mongoose's official guide to getting started with transactions with more info.
@vkarpov15 there are no infos about replica sets in the doc that you linked...Is that impossible to use transaction without replica set or installing a global npm dependency ?
It is unusable for me to use run-rs
because I'am working with electron and cannot install a global npm dependency on the clients machine.
@sebRomeo you should be able to use run-rs independently of electron. Or you can set up a replica set yourself. Unfortunately, MongoDB currently requires replica sets for transactions.
https://www.mongodb.com/docs/manual/tutorial/convert-standalone-to-replica-set/
This is how, you'll fix it in a mac:
Start mongo shell
mongosh
Now in mongoshell run below
use admin
db.adminCommand(
{
shutdown: 1,
comment: "Convert to cluster"
}
)
Now open mongo configuration file
nano /opt/homebrew/etc/mongod.conf
Paste below content
replication:
replSetName: rs0
Now run below commands:
# Server must have stopped
brew services info mongodb/brew/mongodb-community
# Now restart server
brew services restart mongodb/brew/mongodb-community
# Now open mongoshell
mongosh
Now create replica set
rs.initiate()
# To view the replica set configuration
rs.conf()
# To check the status of the replica set
rs.status()
Done
db.adminCommand( { shutdown: 1, comment: "Convert to cluster" } )
MongoNetworkError: connection 5 to 127.0.0.1:27017 closed
gives this error, tried multiple things but couldn't understand why it is showing connection closed.
db.adminCommand( { shutdown: 1, comment: "Convert to cluster" } ) MongoNetworkError: connection 5 to 127.0.0.1:27017 closed
gives this error, tried multiple things but couldn't understand why it is showing connection closed.
@marvellouschandan
@ishaangupta-YB you're sending a shutdown command, so the server you're connected to is shutting down, that's why you're getting a connection closed error
Why replica set required? It makes no sense to me and seems this was a blunder on the Mongodb team.
More info on why replica sets required for transactions here: https://www.mongodb.com/community/forums/t/why-replica-set-is-mandatory-for-transactions-in-mongodb/9533
I had tried transactions. An error occurs when you put options. Brothers find problems .....plz I followed the example here and followed it. http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html However, an error occurs. I need a transaction.
Delete the option and it will work normally....
this is code
this is error message