MongoDB findOne() not doing search, please help

I’m trying to search the order_id in my MongoDB atlas collection , I tried many steps but I’m unable to find the correct solution.

I have a separate API which has data of all the orders and it goes on increasing as new orders arrive, I just want to add only new orders to my MongoDB collection , but when I execute the following code it appends it in the collection without checking that it already exists or not.

		let parsed_response = JSON.parse(res);
		var l = parsed_response.length;
		for (var i = 0; i < l; i++) {
				"order_id": parsed_response[i].id,
				"order_number": `${parsed_response[i].number}`,
				"name": parsed_response[i].shipping.first_name + " " + parsed_response[i].shipping.last_name,
				"address_line_1": parsed_response[i].shipping.address_1,
				"address_line_2": parsed_response[i].shipping.address_2,
				"date": parsed_response[i],
				"city": parsed_response[i],
				"postcode": parsed_response[i].shipping.postcode,
				"state": parsed_response[i].shipping.state,
				"country": parsed_response[i],
				"ordered_item_id": parsed_response[i].line_items[0].id,
				"ordered_item_name": parsed_response[i].line_items[0].name,
				"ordered_item_quantity": parsed_response[i].line_items[0].quantity,
				"payment_method": parsed_response[i].payment_method_title
			}, () => {
				console.log("Added to database");

I tried doing the search with

findOne({ "order_id": parsed_response[i].id })

but i am totally lost. Please help

First, post in one forum or the other. Cross-posting across different topics will largely just annoy everyone.

Second, there’s not enough for us to go on here. What is your schema? Have you (for example) defined order_id as a unique value? If you have, then inserting a record with a duplicate order_id should trigger the error callback. For more about creating a unique index, take a look at the section ‘Indexes’ on

This is all kind of off-the-cuff, again - there’s not really enough to say exactly what’s going on.

where in your code is “product_id”?

Also you have no code for

You need to give more code, a link to the challenge, or something to give more context or it is very difficult to offer help.