Not sure if it’s related but I would suggest you start by using the versions of the packages you are asked to in the starting challenge.
It doesn’t look like an error in the code (works for me). Maybe try manually cleaning the collections on mongodb atlas before submitting again (select the project from the dropdown and click the Browse Collections button, you can then manually delete stuff).
Thank you very much for your info. I downgraded the versions of Mongoose and MongoDB what fcc asked and deleted the previous collections. Problem is still unchanged.
If I fork your code and add my own DB it passes the test. So I’d think it must be the DB. Did you delete everything? Or maybe try deleting the DB completely and creating a new one.
BTW, your mongodb version is still a major version above the one asked for (mongodb@~3.6.0). But as said the fork worked for me.
Yes, now I tried with older versions followed by fcc. Unfortunately, no luck… I deleted the collection in DB. Also tried by opening another account in MongoDB.
Edit: Sorry I didn’t notice your Schema. It is the unique: true option. Delete the “people” collection and remove that option. It now should work with remove and keep working.
I just test it again with the same DB and now I get the same error. So I looked in the DB and I still see one of the “Mary” documents under the “people” collection. If I delete the “people” collection it passes again, I then ran it again it passed, I then ran it again and it failed.
If I switch to deleteMany instead it seems to keep working and still passes the test. You still have to delete the “people” collection first.
I don’t know enough about mongodb to give you a good explanation but the change to Unique Indexes might be related.
The test is creating two docs both with the name Mary.
(getUserInput) =>
$.ajax({
url: getUserInput('url') + '/_api/remove-many-people',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify([
{ name: 'Mary', age: 16, favoriteFoods: ['lollipop'] },
{ name: 'Mary', age: 21, favoriteFoods: ['steak'] }
])
}).then(
(data) => {
assert.isTrue(!!data.ok, 'The mongo stats are not what expected');
assert.equal(
data.n,
2,
'The number of items affected is not what expected'
);
assert.equal(data.count, 0, 'the db items count is not what expected');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
If you keep the server running as you delete the collection it will work, but if you restart the server it will fail again. There also seems to be some weird timing issue because if I use Postman it seems like I can keep getting it to pass after deleting the collection (fairly consistently), but if I use the submit form it fails after two or three tries.