Cosmos DB doesn't support MongoDB `hello` command

Zhanming Cui 20 Reputation points
2025-02-04T11:41:52.6333333+00:00

Hi, MongoDB is using "hello" command for handshaking health check. However, CosmosDB doesn't support it, and all the application development frameworks have switched from isMaster command to this now, which is creating dirty overriding layer in application now.

Can you please support this hello command?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,749 questions
0 comments No comments
{count} votes

Accepted answer
  1. Deepanshu katara 13,285 Reputation points MVP
    2025-02-05T17:03:37.98+00:00

    Hello ,

    Issue - Cosmos DB doesn't support MongoDB hello command

    Solution -->The hello command is not fully supported in Cosmos DB. However, db.hello() is supported, along with db.runCommand({ hello: 1 })." This is work around solution only we do not have complete permanent fix solution to this.Check this link --> https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/mongo/MongoHealthIndicator.javaPlease check and accept

    Thanks

    Deepanshu


2 additional answers

Sort by: Most helpful
  1. Deepanshu katara 13,285 Reputation points MVP
    2025-02-04T12:21:34.46+00:00

    Hello , Welcome to MS Q&A

    Cosmos DB does support the "hello" command for MongoDB handshaking. This command is supported in multiple versions of Azure Cosmos DB for MongoDB, including versions 4.0, 4.2, 5.0, 6.0, and 7.0.

    So basically you need to make sure that you have this version for cosmosDB

    Please check and let us know

    Kindly accept if it helps

    Thanks
    Deepanshu


  2. Dimitri M 0 Reputation points
    2025-02-05T20:37:45.75+00:00

    As I mentioned in the other answer, the problem is that Cosmos DB isn't fully compatible with MongoDB. It does support the shell command db.hello(), but it doesn't support the database command db.runCommand({hello: 1}).

    Currently there's no solution to this problem as it's something Microsoft has to fix themselves. A workaround for Spring Boot is to disable the existing healthcheck by setting the management.health.mongo.enabled property and by defining your own health indicator. Calling a shell command from the Java driver isn't possible as far as I know, so I would use another database command in stead.

    I suggest using the buildInfo database command and to write an indicator like this:

    @Component
    public class MongoHealthIndicator extends AbstractHealthIndicator {
    	private final MongoTemplate mongoTemplate;
    
    	public MongoHealthIndicator(MongoTemplate mongoTemplate) {
    		super("MongoDB health check failed");
    		Assert.notNull(mongoTemplate, "'mongoTemplate' must not be null");
    		this.mongoTemplate = mongoTemplate;
    	}
    
    	@Override
    	protected void doHealthCheck(Health.Builder builder) throws Exception {
    		Document result = this.mongoTemplate.executeCommand("{ buildInfo: 1 }");
    		builder.up();
    	}
    
    }
    
    

    Alternatively, you could downgrade to any Spring Boot version before 3.2.7, but I wouldn't recommend that. For a full overview and my implementation of the reactive health indicator you could check my dedicated blogpost about it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.