angelmunoz / mondocks Goto Github PK
View Code? Open in Web Editor NEWAn alternative way to interact with MongoDB databases from F# that allows you to use mongo-idiomatic constructs
License: MIT License
An alternative way to interact with MongoDB databases from F# that allows you to use mongo-idiomatic constructs
License: MIT License
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.
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
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.
{
"_id": "foo",
"Active": true,
"LicenseInfo": {
...
},
...
}
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.
taken from #1
Add proper documentation explaining the use cases of this library as well it's computation expressions
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)
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
Since this library produces JSON testing should not be complicated at all we just need to check against an existing JSON for each command
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
I took a few notes from Twitter earlier today
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.