orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift
MIT License
717 stars 102 forks source link

Cannot create dynamic Document for arrays and nested jsons #45

Closed sujaykakkad closed 7 years ago

sujaykakkad commented 8 years ago
var username = "mongo"
var array = [1,2,3,4]
var dict = ["name": "kitten", "type": "cat"]

let userCollection = database["users"]

let userDocument: Document = [
            "username":  .string(username),
            "array": .array(arr),
            "dictionary": .array(dict),
        ]

try userCollection.insert(userDocument)
error: cannot convert value of type '[Int]' to expected argument type 'Document'
              array: .array(array),
                            ^~~~~

Why do you need Document type and why can't we create it dynamically?

Please provide JSON or Dictionary datatype support for queries in mongodb or atleast provide raw query support so that we can use raw strings to query mongo database