Giter VIP home page Giter VIP logo

Comments (6)

zonyitoo avatar zonyitoo commented on July 29, 2024

If I understand it correctly, what you want is removing to_json and from_json for BSON? That's impossible. It is necessary for mongo's shell.

BSON to JSON specification is defined here.

from bson-rust.

Matrix-Zhang avatar Matrix-Zhang commented on July 29, 2024

nope, for example, the web sent param as "{"name":"elton", "female": false}", the web server's handle should use to_bson(&param).to_extended_document() to store into mongodb directly, not convert to json first

from bson-rust.

zonyitoo avatar zonyitoo commented on July 29, 2024

Why would you say that Bson will convert to JSON first?

from bson-rust.

zonyitoo avatar zonyitoo commented on July 29, 2024

Ok, I see what you mean. What you want is a wrapper of

let json_str = ...;
let bson = Bson::from_json(&json_str.parse::<Value>().unwrap());

from bson-rust.

zonyitoo avatar zonyitoo commented on July 29, 2024

I would argue that this is not a real demand. Because it is your responsibility to convert the input string to serde_json::Value, not me.

As you can see in serde_json's document, it also provides

  • from_iter
  • from_reader
  • from_slice
  • from_str

for converting inputs to a Value, so I should also provide Bson::from_json_iter, Bson::from_json_reader ... bla bla. No. I don't think so.

In real production code, you must write code like this

let input = ...; // Input value

// **You have to handle this error in your code**
let json = try!(input.parse::<Value>());

// and then generate a valid Bson
let bson = Bson::from_json(json);

// ... #59 value getter
let doc = bson.as_document().unwrap();

// ...

from bson-rust.

zonyitoo avatar zonyitoo commented on July 29, 2024

Closed for rejected.

from bson-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.