Jump to content
Forumu Destekleyenlere Katılın ×
Paticik Forumları
2000 lerden beri faal olan, çok şukela bir paylaşım platformuyuz. Hoşgeldiniz.

MongoDB sorusu


Öne çıkan mesajlar

Mesaj tarihi: (düzenlendi)

ya arkadaş çıldırıciğim

 

mERN uygulama yapıyorum, Rreact Node Express MongoDB

mongodb den id den çekip delete yapamıyor bir türlü; backend kod şu:

const ObjectID = require("mongodb").ObjectID;

 

router.delete("/:id", auth, (req, res) => {

  var id = ObjectID(req.params._id);

 

  Item.deleteOne({ _id: id })

    .then((result) => {

      console.log(result);

      res.json({ success: true });

    })

    .catch(err => {

    // console.log(err);

      res.status(404).json({ success: false });

    });

});

 

then kısmına giriyor yani method başarılı ama hiçbirşey simiyor, yukardaki result konsol log u ise şöyle: 

 

Spoiler

0] { n: 0,
[0]   opTime:
[0]    { ts:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      t: 8 },
[0]   electionId: 7fffffff0000000000000008,
[0]   ok: 1,
[0]   operationTime:
[0]    Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]   '$clusterTime':
[0]    { clusterTime:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      signature: { hash: [Binary], keyId: [Long] } },
[0]   deletedCount: 0 }
[0] { n: 0,
[0]   opTime:
[0]    { ts:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      t: 8 },
[0]   electionId: 7fffffff0000000000000008,
[0]   ok: 1,
[0]   operationTime:
[0]    Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]   '$clusterTime':
[0]    { clusterTime:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      signature: { hash: [Binary], keyId: [Long] } },
[0]   deletedCount: 0 }
[0] { n: 0,
[0]   opTime:
[0]    { ts:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      t: 8 },
[0]   electionId: 7fffffff0000000000000008,
[0]   ok: 1,
[0]   operationTime:
[0]    Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]   '$clusterTime':
[0]    { clusterTime:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      signature: { hash: [Binary], keyId: [Long] } },
[0]   deletedCount: 0 }
[0] { n: 0,
[0]   opTime:
[0]    { ts:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      t: 8 },
[0]   electionId: 7fffffff0000000000000008,
[0]   ok: 1,
[0]   operationTime:
[0]    Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]   '$clusterTime':
[0]    { clusterTime:
[0]       Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1573904655 },
[0]      signature: { hash: [Binary], keyId: [Long] } },
[0]   deletedCount: 0 }

 

lovecraft0Z tarafından düzenlendi
Mesaj tarihi: (düzenlendi)

const Item = require("../../models/Item");

 

şurada:
collection yok zaten. db.collection yazınca o bir fonskyon değil hatası veriyor, tam anlayamadım o mantığı
 

const mongoose = require("mongoose");

const Schema = mongoose.Schema;

 

//Create Schema

const ItemSchema = new Schema({

  name: {

    type: String,

    required: true

  },

  createdAt: {

    type: Date,

    default: Date.now

  },

  handler:{

    type:String,

    required:true

  }

});

 

module.exports = Item = mongoose.model("item", ItemSchema);

 

lovecraft0Z tarafından düzenlendi
Mesaj tarihi:

Bu arada id yi elle string olarak girince siliyor. Anladığım kadarıyla objectID aynı işi yapıyor ama number gönderiyor, o numberı string yapmalıyım diye düşünüyorum ama beceremedim. yoksa console layınca ikiside aynı sonucu basıyor, ama elle girdiğim siliyor, objectId(req.params._id) ile girdiğim silResmin linkini yapıştırınmiiyor

Mesaj tarihi:

YA şimdi de durup duruken db ye bağlanamıyor şu hatayı veriyor var mı aşinalığı olan: 

{ MongoTimeoutError: Server selection timed out after 30000 ms [0] at Timeout.setTimeout (C:\Users\onert\OneDrive\Desktop\reactJs\mern_shopping_list\node_modules\mongodb\lib\core\sdam\topology.js:878:9) [0] at ontimeout (timers.js:436:11) [0] at tryOnTimeout (timers.js:300:5) [0] at listOnTimeout (timers.js:263:5) [0] at Timer.processTimers (timers.js:223:10) [0] name: 'MongoTimeoutError', [0] reason: [0] { MongoNetworkError: connection 2 to mernshopping-shard-00-00-nixua.mongodb.net:27017 closed [0] at TLSSocket.<anonymous> (C:\Users\onert\OneDrive\Desktop\reactJs\mern_shopping_list\node_modules\mongodb\lib\core\connection\connection.js:356:9) [0] at Object.onceWrapper (events.js:273:13) [0] at TLSSocket.emit (events.js:182:13) [0] at _handle.close (net.js:606:12) [0] at TCP.done (_tls_wrap.js:386:7) [0] name: 'MongoNetworkError', [0] errorLabels: [ 'TransientTransactionError' ], [0] [Symbol(mongoErrorContextSymbol)]: {} }, [0] [Symbol(mongoErrorContextSymbol)]: {} }

 

Mesaj tarihi:

ObjectId yi new ile initialize etmen lazim. ama direkt string passlarsan mongoose her turlu casti halleder senin icin. 

es6 veya TS kullanmani tavsiye ederim bu arada. Cok daha eglenceli bi developmentin olur

Mesaj tarihi:

javascript maalesef boyle, koli bandindan dil yaparsan olacagi bu ?

FE’de mecburuz da backendde uzak durmakta fayda var

1 saatini ayirip python kutuphanesinin dokumentasyonunu oku 1 saat de js olanini, pythonu bilmesen bile farki goreceksin nasil clearly defined her sey statically typed olmamasina ragmen

Mesaj tarihi:

Ben bunu çözdüm ya ön yüzden yanlış gönderiyomuşum id'yi

ES6 kullaniyorum ya önde, reactla zaten lazım.
Ben react yaparken bacckendde de bi CRUD yapabileceğim basit ne olur dedim oradan MERN stack olayına girdim o yüzden node-express 

×
×
  • Yeni Oluştur...