Giter Site home page Giter Site logo

angelmunoz / mondocks Goto Github PK

View Code? Open in Web Editor NEW
44.0 4.0 4.0 417 KB

An alternative way to interact with MongoDB databases from F# that allows you to use mongo-idiomatic constructs

License: MIT License

F# 70.53% Jupyter Notebook 25.91% Dockerfile 2.81% Nix 0.76%
mongodb fsharp computation-expressions nosql library dotnet dotnet5 dotnet-core mongo

mondocks's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mondocks's Issues

Serialization errors with `FindResult`, `DeleteResult` on dotnet

Running the examples in samples/Commands fails because the MongoDB driver expects certain fields that don't exist in a FindResult<'T> or a UpdateResult to actually exist.

On my end, I can confirm that simply doing

[<BsonIgnoreExtraElements>]
type FindResult<'T> = { cursor: Cursor<'T>; ok: float }

resolves this (because Mongo also returns the operationTime field).

However, it's not just this one simple fix; the update command still fails because of the same issue. My conclusion is that we'll have to add this attribute to all of the types in Mondocks.Net's Types.fs; it follows that it might not make sense to share the types between Mondocks.Net and Mondocks.Fable?

Finally, a small feature request/design question: what determines which fields make it into the result structs? It would be nice, for instance, to also be able to also inspect the upserted items of an UpdateResult. See output reference here.

Make it available for Node

Most of the builders don't use the Mongo.BsonId package it's basically used at the end to generate the final JSON, and it is basically used just to add some serializers but if we switch to Thoth.Json perhaps we should be able to drop that dependency and allow the library to be used from .NET and Node

Query for a subset of the document

It should be possible to define a document only partially and the query should still work.
At the moment I have to define every JSON field or else I get a FormatException.

Example:

Document

{
  "_id": "foo",
  "Active": true,
  "LicenseInfo": {
    ...
  },
  ...
}

Query

type Poi =
  { _id: string
    Active: bool }

let q = find "pois" { ... }
db.RunCommandAsync<FindResult<Poi>>(JsonCommand q)
System.FormatException: An error occurred while deserializing the cursor property of class Mondocks.Types.FindResult`1[[FSI_0063+Poi, FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]: An error occurred while deserializing the firstBatch property of class Mondocks.Types.Cursor`1[[FSI_0063+Poi, FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]: Element 'LicenseInfo' does not match any field or property of class FSI_0063+Poi. ---> System.FormatException: An error occurred while deserializing the firstBatch property of class Mondocks.Types.Cursor`1[[FSI_0063+Poi, FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]: Element 'LicenseInfo' does not match any field or property of class FSI_0063+Poi. ---> System.FormatException: Element 'LicenseInfo' does not match any field or property of class FSI_0063+Poi.
   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)

Especially in a production environment, where the document schema can grow independently from your application code this ends up in runtime errors that can easily avoided by allowing to map to a subset of the document.

Add Docs

Add proper documentation explaining the use cases of this library as well it's computation expressions

Filter with int default (0) value.

With options.DefaultIgnoreCondition <- JsonIgnoreCondition.WhenWritingDefault settings expression like this:

find "users" {
    filter {| age = {| ``$gt`` = 0 |} |}
    limit 5
}

is producing this json:

{"find":"users","filter":{"age":{}},"limit":{"$numberInt":"5"}}

and we get no documents.

But with options.DefaultIgnoreCondition <- JsonIgnoreCondition.WhenWritingNull:

{"find":"users","filter":{"age":{"$gt":{"$numberInt":"0"}}},"limit":{"$numberInt":"5"}}

and filter works as expected.

I suppose you should replace the settings in default serializer options.

Affected version: Mondocs.Net (0.4.8)

Investigate helper functions

taken from #1
add method helpers to create things like filters, fields, matching criteria

examples of this can be

find "users" {
  filter (fun m -> m.prop = value)
}

or

find "users" {
  filter "prop" gt 10
}

the main blocker right now for this is that in any case, we must emit 100% compatible JSON to https://docs.mongodb.com/manual/reference/command/
so there needs to be some investigation around this if this is something people want to add into the mix

Add Tests

Since this library produces JSON testing should not be complicated at all we just need to check against an existing JSON for each command

Explore default BSON serialization

There's the possibility that we can just serialize known BSON values in the emitted JSON, as the MongoDB Extended Spec shows, we're kind of doing half work for ObjectIds so instead of just emitting the "objectid" we could be emitting { $oid: "objectid" } in the same way we could be doing the same for int64, dates, etc

Ideally I'd like to use the canonical form when possible, but if there's not an option using the relaxed form should be enough

Feedback from twitter

I took a few notes from Twitter earlier today

  • look a way to create indexes
  • remove prefixes from custom operations
  • pass the collection name as the parameter of the CE's
  • return typed results from the command execution
  • add BSON decoders
  • add method helpers to create things like filters, fields, matching criteria

Example of using array filters

Hello!

Can someone show an example of using array filters in queries?
Looks like currently they are represented as just "object" type, so its not clear on how to actually utilize them.

Thank you!

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.