Hello,
I’m trying to work with mongodb and I’m trying to add a record to a collection.
I’m getting the following error in the Site Events Log in the backend code:
"["(node:1) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead."]"
I’m getting the record to add, but to note let me know what the object id is.
My source code:
export async function addRecord(db_name,collection_name,record) {
let item = "";
async function addit() {
await client.connect(err => {
const collection = client.db(db_name).collection(collection_name);
//Start Action: perform actions on the collection object
console.log("hey")
item = collection.insertOne( { item: "card", qty: 155 } )
//End Action
//client.close();
});
}
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://...";
const client = new MongoClient(uri, {useNewUrlParser: true, useUnifiedTopology: true});
let data = await addit()
return data
}
Can you help? Thank you!
Thank you, yes I saw all of that, but even with the code below I’m getting the error.
export async function addRecord(db_name,collection_name,record) {
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://...";
const client = MongoClient(uri, {useNewUrlParser: true, useUnifiedTopology: true});
await client.connect(err => {
const collection = client.db(db_name).collection(collection_name);
let doc = record;
collection.insertOne(doc, async function (error, response) {
let data = await response.ops[0];
console.log(data)
});
client.close();
});
}
Unsure what I’m missing here.
Ais I’ve already stated from previous links about it…
This is not an error, it is a warning that this method of creating a buffer is deprecated:
https://nodejs.org/api/buffer.html#buffer_new_buffer_string_encoding
As you state already…
I’m getting the record to add, but to note let me know what the object id is.
So the code still all works fine, you just need to look into the Mongo change with the method of creating a buffer is depreciated and see if it would affect anything in your codings and to see if you would or could change it if needed.
That is something you would have to do yourself through Mongo own support and not through Wix as Mongo is a seperate company.