[CSHARP-3279] Validation on double type Created: 02/Dec/20  Updated: 27/Oct/23  Resolved: 18/Dec/20

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.11.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Pablo Echavarría. Assignee: Robert Stam
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

.net core, compass


Attachments: PNG File image-2020-12-02-12-38-12-267.png     PNG File image-2020-12-02-12-42-59-759.png     PNG File image-2020-12-02-12-44-51-133.png     PNG File image-2020-12-02-12-45-45-570.png     PNG File image-2020-12-02-12-45-56-863.png    

 Description   

Validation fails for double type when value ends in .0

it passes the validation for 10.1 but not for 10 for example,

tested on compass, and .net core mongo db driver



 Comments   
Comment by Backlog - Core Eng Program Management Team [ 18/Dec/20 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Robert Stam [ 03/Dec/20 ]

I am unable to reproduce this using the C# driver. The C# driver works as expected.

I used the following self-contained console test application:

using MongoDB.Bson;
using MongoDB.Driver;
 
namespace TestCSharp3279
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("test");
            var collection = database.GetCollection<BsonDocument>("test");
 
            database.DropCollection("test");
            CreateCollectionWithJsonSchema(database, "test");
 
            var document1 = new BsonDocument("ph"1.0); // this document passes validation
            collection.InsertOne(document1);
 
            var document2 = new BsonDocument("ph"2); // this document does not pass validation (because 2 is an integer, not a double)
            collection.InsertOne(document2);
        }
 
        private static void CreateCollectionWithJsonSchema(IMongoDatabase database, string collectionName)
        {
            var jsonSchema = BsonDocument.Parse(
                @"
                {
                    bsonType : 'object',
                    required : ['ph'],
                    properties : {
                        'ph' : { bsonType : 'double' }
                    }
                }
                ");
 
            var createCollectionCommand = BsonDocument.Parse(
                @"
                {
                    create : '<placeholder>',
                    validator : { $jsonSchema : '<placeholder>' },
                    validationLevel : 'strict',
                    validationAction : 'error'
                }
                ");
            createCollectionCommand["create"] = collectionName;
            createCollectionCommand["validator"]["$jsonSchema"] = jsonSchema;
 
            database.RunCommand<BsonDocument>(createCollectionCommand);
        }
    }
}

Take a look at my repro and let me know if I am doing something different than you are.

Regarding Compass, any issues in Compass should be reported as a ticket in the Compass Jira project:

https://jira.mongodb.org/projects/COMPASS

Comment by Robert Stam [ 03/Dec/20 ]

Thanks for clarifying that the type of validation you were referring to was $jsonSchema validation.

I will attempt to reproduce this with the C# driver.

Comment by Pablo Echavarría. [ 02/Dec/20 ]

The validation of the collection looks like:

The document to be inserted looks like this:

And as you can see it fails validation.

 

And an example that succeed validation looks like:

(note that document with ph: 1.0 is unable to be inserted).

 

This example was using mongodb compass, however is the same

case for when I try with the c# mongodb client.

 

 

 

 

 

Comment by Robert Stam [ 02/Dec/20 ]

Thanks for reporting this issue. Please provide a [minimal reproducible example https://stackoverflow.com/help/minimal-reproducible-example] to help us debug it.

Generated at Wed Feb 07 21:44:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.