Can not get document DB when using seesion - node.js

I'm trying to create a transaction with my document DB version 4.0.0.
I was able to open a session but when I try to get the database information I get this error messages:
session.getDatabase is not a function
let session = await beginTransaction('matan');
let assetSessionObject = session.getDatabase('matan').getCollection('test');
I'm using mongodb: 3.6.6 driver from, So maybe the problem is that there is no driver 4.0.0 yet?
Thanks

You're going to want to upgrade to a MongoDB driver that is compatible with 4.0. Even though sessions came out in MongoDB 3.6, if you want to use transactions with Amazon DocumentDB or MongoDB, you're going to have to upgrade to 4.0 compatible drivers anyways as that's major version when transactions was introduced.

Related

Couchbase Java SDK subdocument mutation

Hi Im running couchabse server 7.1.3 docker container and trying to use the 3.3.4 couchbase java sdk version. I am facing an issue while performing subdocument mutation using the upsert command.
The issue I am facing is when I use the collection.mutateIn() method to perform a subdocument mutation using the upsert command, I am expecting to get the result of the operation as a MutateInResult object. when I try to use the MutateInResult.contentAs(0, String.class) to see the response I get the Index 0 is invalid error. I see that the operation as in is successful in the DB, I can see the desired json path has the updated value.
P.S: I only have a single mutation to perform which is the upsert command.
can someone please help if I am missing something here?

Mongo doesn't save data into disk

In our project we often have a problem when mongo doesn't save its state into disk, and after rebooting the application we lose data. I could not determine when and why this happens - somehow and somewhen :). Does anybody know how to synchronize mongodb storage to disk with some api? We use mongorito ODM. PLeasure to hear any variants.
Some details.
Mongo version 3.2.
Application - it is an electron application. Under the hood it uses mongo as storage - we use mongo on client side and install it as a windows service advantagely. Application starts, makes different transactions, read/write data from/to mondo db - nothing strange. When we close this application and reopen next time - we cannot find last rows (documents) in some collections that were succesfully (according to mongo answers) saved. We have no errors.
Can anyone explain what the write concern is and how to setup it not to wait 60 seconds before flushing the data - may be this is the reason?
Some code of db connect/disconnect. app means an electron application:
const {Database} = require('mongorito');
const db = new Database(__DBPATH__);
db.connect();
db.register(__MONGORITO_MODEL__);
app.on('window-all-closed', () => {
db.disconnect();
});
I'd take a look at the write concern setting within your application and make sure it's set to the requirements of your business - https://docs.mongodb.com/manual/reference/write-concern/
Also, make sure you're running a replica set in your production environment 👍
Thanks to everyboy, I've solved the problem. The reason was the journaling. I turn on the journaling for mongodb service and the problem has gone.
mongod.exe --journal

MongoDB transaction vs firebase transaction

Question1:
Is mongoDB transaction available in Nodejs? or is it only available for Python and Java at the moment?
Java
try (ClientSession clientSession = client.startSession()) {
clientSession.startTransaction();
collection.insertOne(clientSession, docOne);
collection.insertOne(clientSession, docTwo);
clientSession.commitTransaction();
}
Python
with client.start_session() as s:
s.start_transaction()
collection_one.insert_one(doc_one, session=s)
collection_two.insert_one(doc_two, session=s)
s.commit_transaction()
Question2:
If there are 2 users calling the same API at the same time updating the same document, will transaction solve the race condition. Where it will wait for the 1st process of user 1 reading and updating the document and only process the 2nd process of user 2 reading and updating the document?
Previously, when using firebase cloud function, I'm able to solve this issue using transactions. Not sure if it's the same thing

Express with Azure cosmos DB

Working with express(nodejs), mongoose, and Azure Cosmos DB to return objects.
When I connect to my local mongodb, the following code correctly returns a list of commit objects that exist in local mongodb.
Commit
.find({}, function(err, commits) {
if (err) {
res.render('search/index', {});
} else {
res.json(commits);
}
});
However, when connecting to Azure Cosmos DB using a PRIMARY CONNECTION STRING shown on my Azure portal website, the code just returns an empty list.
I checked that the mongoose.connection.readyState value is 1.
In addition, I can connect to the Azure Cosmos DB using Robo 3T.
Mongoose was designed to work with MongoDB. If your local testing with a real MongoDB server yields the expected result, then the fault is unlikely to be in mongoose or your code. Since CosmosDB only attempts to mimic MongoDB's API, there is no guarantee that it will work the same way. In your case, apparently it doesn't.
Being able to connect to CosmosDB using tools designed to work with MongoDB doesn't necessarily mean that CosmosDB will return the correct result.
If you require a cloud-based MongoDB deployment, using MongoDB Atlas is likely the best solution at this point in time.
Finally I could solve this problem by myself.
The latest version (v3.1.1) of the library doesn't work for connecting to Azure Cosmos DB.
You should use mongodb 2.2.33.
I found the solution from a comment on https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-samples.

Update SQL Server CE database (.sdf) from 3.5 to 4.0

I need to upgrade a SQL Server Compact database from 3.5 to 4.0 version. I am using linq-to-sql
I tried some things that I found on stackoverflow, that did not help:
I tried Add 4.0 connection dialog (no error messages, bak file was created)
I tried upgrading in code: (no error messages)
System.Data.SqlServerCe.SqlCeEngine engine= new System.Data.SqlServerCe.SqlCeEngine("Data source = ...");
engine.Upgrade();
I checked for database corruption (system returned that there are no corruption problems)
System.Data.SqlServerCe.SqlCeEngine engine= new System.Data.SqlServerCe.SqlCeEngine("Data source = ...");
engine.Verify();
After these operations I wanted to recreate dbml file - I received error message
Incompatible Database Version (..) DB version 4000000, Requested version 3505053 (..)
In debug mode I checked db.Connection.ServerVersion = returns 3.5.8080.0
In database connection properties version is 4.0.8876.1
Any suggestions?
Once you have upgraded your database to 4.0, you can no longer create a dbml file, as the Tool responsible for this only Works with 3.5 databasee files. One possible workaround is to have two version of the database, one 3.5 for dbml generation, and another for use. Remember to initialize the DataContext object with a SqlCeConnection object, otherwise 4.0 will not Work with LINQ to SQL - or you can try my SQL Server Compact Toolbox, that allows you to generate a DataContext directly from a 4.0 database file (must still initialize with SqlCeConnection object)

Resources