2

I am implementing Microservices in Flask application.

Service A runs on MySQL and Service B runs on MongoDB using pymongo.

The ID from Service B is linked as an Integer field in MySQL.

Is it possible to make MongoDB generate '_id' as a sequence of just numbers instead of alphanumeric characters or should I go about changing the schema of MySQL ?

Febin Peter
  • 805
  • 1
  • 7
  • 10

1 Answers1

6

Mongo directly won't do that, But you can do that by yourself. Send _id as a unique number to mongo while storing as document and it will accept it.

> db.a.insert({_id:111})
WriteResult({ "nInserted" : 1 })

In fact you can use auto-incremented _ids as well using this

Akarsh Satija
  • 1,756
  • 2
  • 22
  • 28