Uncaught (in promise) TypeError: itemsCollection.remove is not a function at stClient.login.then

Uncaught (in promise) TypeError: itemsCollection.remove is not a function at stClient.login.then

我是 Mongodb 的新手,我正在尝试使用 JS 创建简单的 HTML,其中可以在 Cloud Atlas 上的 Mongodb 数据库中添加和删除用户。添加用户工作正常。但由于某种原因,无法识别删除功能。 应用程序 ID 是 --> "facebookclone- tlwvi" 我将分离 js 代码,下面是现在的代码:

<!DOCTYPE html>
<html>
<head>
<title>myFb</title>

 <link rel="stylesheet" type="text/css" href="style1.css">
<script src="https://s3.amazonaws.com/stitch- 
sdks/js/library/v3/stable/stitch.min.js"></script>

<script>
let db;
let itemsCollection;
let stClient;
let clientPromise = stitch.StitchClientFactory.create('facebookclone- 
tlwvi');


function onLoadConnectDB(){
    clientPromise.then(stitchClient=>{
        stClient=stitchClient;
        db = stClient.service('mongodb', 'mongodb-atlas').db('FbUsers');
        itemsCollection=db.collection("ClonedFbUsers");
    });

}

 function addUser(){
 var n= prompt("Your username: ")
const userId = stClient.authedId();
stClient.login().then(()=>
    itemsCollection.insertOne({ owner_id: stClient.authedId(), userName : n 
, profilePhoto: "NULL", photos: ["NULL"],comments: 
 [{msg:"NULL",time:"NULL",like:0}] })
    ).then(() => itemsCollection.find({}).execute())
  .then(docs =>
  docs.forEach((doc, index) =>
    console.log(`${index}: ${JSON.stringify(doc)}`)
    )
  );
alert("added");
}

 function deleteUser(){

var d= prompt("Username to delete: ");
const userId = stClient.authedId();

stClient.login().then(()=>
    itemsCollection.remove({ userName: {$eq: d} })
    ).then(() => itemsCollection.find({}).execute())
.then(docs =>
  docs.forEach((doc, index) =>
    console.log(`${index}: ${JSON.stringify(doc)}`)
    )
  );
alert("User "+d+ " deleted.");


}

</script>
 </head>


 <body onload="onLoadConnectDB()">


<p>Hello My App</p>

<div id="wlcom" align="center">
<button name="adding" onclick="addUser()">Add User</button><br>
<button name="deleting" onclick="deleteUser()">Delete User</button> <br>
<button name="logging">Login</button><br>
 </div>

</body>
</html>

MongoDB remove 方法已弃用。我将其更改为 itemsCollection.deleteOne 而不是 remove,尽管它确实出现了其他错误,但它能够解决 remove 未定义的问题。

使用 deleteOne 导致 HTTP 403(禁止)错误。