MongooseError: Model.findOne() no longer accepts a callback at Function

Mongoose dropped support for callbacks from its node.js driver as of version 5.0. You can use async/await instead: module.exports = { data: new SlashCommandBuilder().setName(‘dbtest’).setDescription(‘db test’), async execute(interaction) { try { const data = await testSchema.findOne({ GuildID: interaction.guild.id, UserID: interaction.user.id, }); if (!data) { testSchema.create({ GuildID: interaction.guild.id, UserID: interaction.user.id, }); } if (data) { console.log(data); } … Read more

MongoDB extracting values from BasicDBObject (Java)

There’s no way to chain a property name like you’re doing using the Java driver (gets for sure, and according to the this, put isn’t supposed to work either). You’ll need to get the objects one at a time like you suggested. ((DBObject)obj.get(“response”)).get(“resData”) See here for a potential future feature that would allow your syntax … Read more

java.lang.NoClassDefFoundError when using MongoDB driver

You have java.lang.NoClassDefFoundError – that means your class is missed during runtime (not during build/compile time). So you should open your “Run Configurations” dialog for the project (project context menu -> “Run As” -> “Run Configurations…”) and make sure you have bson-xxx.jar, mongodb-driver-xxx.jar, and mongodb-driver-core-xxx.jar somehow listed in Classpath tab. And yes, like Xavier Bouclet … Read more

MongoDB database deleted automatically

Hey It is a virus attack read this article https://www.bleepingcomputer.com/news/security/mongodb-apocalypse-professional-ransomware-group-gets-involved-infections-reach-28k-servers/ Actually more than 28k mongodb server have been attacked by the community and they have either deleted the database or have encrypted them. Now they are demanding Bit coin for giving backup. Now the Question arises that is mongoDb safe as so many database have … Read more

How to filter fields from a mongo document with the official mongo-go-driver

Edit: As the mongo-go driver evolved, it is possible to specify a projection using a simple bson.M like this: options.FindOne().SetProjection(bson.M{“_id”: 0}) Original (old) answer follows. The reason why it doesn’t work for you is because the field fields._id is unexported, and as such, no other package can access it (only the declaring package). You must … Read more

How to increment a field in mongodb?

As the error indicates, on the client you can only perform an update with a simple _id selector. I’d recommend using a method with a slight modification to your code: Meteor.methods({ incClicks: function(id, news) { check(id, String); check(news, Match.ObjectIncluding({link: String})); News.update( {_id: id, ‘items.link’: news.link}, {$inc: {‘items.$.clicks’: 1}} ); } }); Here we are using … Read more