Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获(承诺中)类型错误:itemsCollection.remove不是stClient.login.then上的函数_Javascript_Mongodb_Mongodb Atlas_Mongodb Stitch - Fatal编程技术网

Javascript 未捕获(承诺中)类型错误:itemsCollection.remove不是stClient.login.then上的函数

Javascript 未捕获(承诺中)类型错误:itemsCollection.remove不是stClient.login.then上的函数,javascript,mongodb,mongodb-atlas,mongodb-stitch,Javascript,Mongodb,Mongodb Atlas,Mongodb Stitch,我对Mongodb很陌生,我尝试用JS创建简单的HTML,在这里可以在CloudAtlas上的Mongodb数据库中添加和删除用户。添加用户可以很好地工作。但由于某些原因,无法识别remove函数。 应用程序id为-->“facebookclone-tlwvi” 我将分离js代码,下面是目前的代码: <!DOCTYPE html> <html> <head> <title>myFb</title> <link rel="sty

我对Mongodb很陌生,我尝试用JS创建简单的HTML,在这里可以在CloudAtlas上的Mongodb数据库中添加和删除用户。添加用户可以很好地工作。但由于某些原因,无法识别remove函数。 应用程序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>

myFb
让db;
让项目集合;
让stClient;
让clientPromise=stitch.StitchClientFactory.create('facebookclone-
tlwvi');
函数onLoadConnectDB(){
然后(stitchClient=>{
stClient=缝合客户端;
db=stClient.service('mongodb','mongodb-atlas').db('FbUsers');
itemsCollection=db.collection(“ClonedFbUsers”);
});
}
函数addUser(){
var n=prompt(“您的用户名:”)
const userId=stClient.authedId();
stClient.login()。然后(()=>
itemsCollection.insertOne({owner\u id:stClient.autheId(),用户名:n
,profilePhoto:“空”,照片:[“空”,评论:
[{msg:“NULL”,time:“NULL”,如:0}]})
).then(()=>itemsCollection.find({}).execute()
。然后(docs=>
docs.forEach((doc,index)=>
log(`${index}:${JSON.stringify(doc)}`)
)
);
警告(“添加”);
}
函数deleteUser(){
var d=提示(“要删除的用户名:”);
const userId=stClient.authedId();
stClient.login()。然后(()=>
itemsCollection.remove({userName:{$eq:d}})
).then(()=>itemsCollection.find({}).execute()
。然后(docs=>
docs.forEach((doc,index)=>
log(`${index}:${JSON.stringify(doc)}`)
)
);
警报(“用户”+d+“已删除”);
}
你好,我的应用程序

添加用户
删除用户
登录

MongoDB
remove
方法已被弃用。我将此更改为
itemsCollection.deleteOne
而不是
remove
,虽然它确实收到了其他错误,但它能够克服您提出的
remove
未定义的问题


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

奇怪。插入时不应该出现相同的错误吗?我不知道为什么要删除。我正在添加一个屏幕截图,以防有人愿意提供帮助。感谢您在插入时不尝试调用
remove
。我想我很清楚为什么要删除。你还需要什么帮助?我说的是HTTP 403(禁止)错误。deleteOne操作的禁止错误的原因是什么?如果是权限的情况,那么为什么插入不会导致相同的错误?好吧,这是一个不同的问题!虽然您在这个问题中没有关于您的设置和配置的任何信息,但通常403表示,尽管您已通过身份验证,但您未获得授权。你有合适的角色吗?角色名称是否以“角色”开头?如果您对403问题有任何疑问,请提出一个新问题,重点关注该问题。