Laravel MongoDB:点必须仅包含数字元素

时间:2018-06-25 19:08:02

标签: mongodb laravel-5.2

我正在尝试将自己的集合或坐标用于GeoWithin

//This is our test data
var input = @"{
    ""id"": 123,
    ""userName"": ""fflintstone"",
    ""address"": ""345 Cave Stone Road"",
    ""address2"": """",
    ""city"": ""Bedrock"",
    ""state"": ""AZ"",
    ""zip"": """"   
}";

//This anonymous type will be used as a template to deserialize the test data
var template = new 
{ 
    id = default(int),
    userName = default(string),
    address = default(string),
    address2 = default(string),
    city = default(string),
    state = default(string),
    zip = default(string)
};

//Deserialize
var temp = JsonConvert.DeserializeAnonymousType(input, template);

//Use the deserialized object to create an AddressModel
var address = new AddressModel
{
    Address = temp.address,
    Address2 = temp.address,
    City = temp.city,
    State = temp.state,
    Zip = temp.zip
};

//Create a customer using the deserialized data and our new AddressModel instance
var customer = new Customer
{
    Id = temp.id,
    UserName = temp.userName,
    Address = address
};

//Output a couple fields to check
Console.WriteLine("{0} {1}", customer.Id, customer.Address.City);

但是,这是我遇到的错误:点只能包含数字元素。 $ shop-> bounds是一个坐标数组。有解决办法吗?

1 个答案:

答案 0 :(得分:0)

尝试将$ shop-> bounds转换为double。