0
mongodb를 사용 중이고 문서를 편집하고 중복되지 않고 다시 삽입하고 싶습니다. 지금까지 나는 collection.findAndModify()를 시도했지만 작동시키지 못했습니다.문서 찾기, 편집 및 다시 MongoDB에 넣기
UserProfiles = [
\t \t {
\t \t \t userProfileID: 1,
\t \t \t firstName: 'Austin',
\t \t \t lastName: 'Hunter',
\t \t \t email: 'ahun.....com',
\t \t \t token: '',
\t \t \t platform: '',
\t \t \t password: 'incorrect',
\t \t \t companyProfileID: 1,
\t \t \t authentication: '',
\t \t \t UserTopics: [
내가이 작업을 수행 할 수 있도록하려면 : - 이메일 일치 검색을 통해 개체의 출력 프로파일을 잡아
일이 같은 컬렉션이 있습니다.
2 - 이메일이 일치하면 토큰 및 플랫폼 항목을 편집하십시오.
3 - 중복되지 않은 문서를 다시 넣습니다. 그래서 그것을 복제하기 때문에 다시 삽입 할 수는 없습니다.
누구나 나를 알아낼 수 있습니까?
코드 :
function registerUser(email, token, platform) {
\t MongoClient.connect(url, function(err, db) {
\t if (err) {
\t \t \t console.log(err);
\t } else {
\t \t \t console.log("We are connected");
\t }
\t \t
\t \t var collection = db.collection('UserProfile');
\t \t collection.findAndModify({
\t query: { email: email },
\t update: { token: token, platform: platform }
});
db.close();
\t
놀랍게도 효과가있었습니다. 정확히 내가 찾는 것처럼. 엄청 고마워. 6 분 안에 최선의 대답을 선택하십시오. –
건배! @AustinHunter –